From 02ceed9f83f82f0de35c7bd73c27a33d4f0fe9cb Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Mon, 8 Aug 2016 09:35:17 +1000 Subject: [PATCH] 4428. [bug] The "test dispatch getnext" unit test could fail in a threaded build. [RT #42979] (cherry picked from commit c4153b554d2982079bb1dd304404837242757ad2) --- CHANGES | 3 +++ lib/dns/tests/dispatch_test.c | 36 ++++++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/CHANGES b/CHANGES index a43bc97699..b4e3fc80fc 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +4428. [bug] The "test dispatch getnext" unit test could fail + in a threaded build. [RT #42979] + --- 9.11.0b3 released --- 4426. [bug] Addressed Coverity warnings. [RT #42908] diff --git a/lib/dns/tests/dispatch_test.c b/lib/dns/tests/dispatch_test.c index 71445aa912..9627e7e065 100644 --- a/lib/dns/tests/dispatch_test.c +++ b/lib/dns/tests/dispatch_test.c @@ -191,26 +191,46 @@ nameserver(isc_task_t *task, isc_event_t *event) { isc_event_free(&event); } +static dns_dispatch_t *dispatch = NULL; static dns_dispentry_t *dispentry = NULL; static isc_boolean_t first = ISC_TRUE; +static isc_mutex_t lock; +static isc_sockaddr_t local; static unsigned int responses = 0; static void response(isc_task_t *task, isc_event_t *event) { dns_dispatchevent_t *devent = (dns_dispatchevent_t *)event; isc_result_t result; + isc_boolean_t wasfirst; UNUSED(task); - if (first) { + LOCK(&lock); + wasfirst = first; + first = ISC_FALSE; + responses++; + UNLOCK(&lock); + + if (wasfirst) { result = dns_dispatch_getnext(dispentry, &devent); ATF_CHECK_EQ(result, ISC_R_SUCCESS); } else { dns_dispatch_removeresponse(&dispentry, &devent); isc_app_shutdown(); } - first = ISC_FALSE; - responses++; +} + +static void +startit(isc_task_t *task, isc_event_t *event) { + isc_result_t result; + isc_socket_t *sock = NULL; + + isc_socket_attach(dns_dispatch_getsocket(dispatch), &sock); + result = isc_socket_sendto(sock, event->ev_arg, task, senddone, sock, + &local, NULL); + ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + isc_event_free(&event); } ATF_TC(dispatch_getnext); @@ -218,11 +238,8 @@ ATF_TC_HEAD(dispatch_getnext, tc) { atf_tc_set_md_var(tc, "descr", "test dispatch getnext"); } ATF_TC_BODY(dispatch_getnext, tc) { - dns_dispatch_t *dispatch = NULL; isc_region_t region; isc_result_t result; - isc_sockaddr_t local; - isc_socket_t *dsock = NULL; isc_socket_t *sock = NULL; isc_task_t *task = NULL; isc_uint16_t id; @@ -233,6 +250,9 @@ ATF_TC_BODY(dispatch_getnext, tc) { UNUSED(tc); + result = isc_mutex_init(&lock); + ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + result = dns_test_begin(NULL, ISC_TRUE); ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); @@ -279,11 +299,9 @@ ATF_TC_BODY(dispatch_getnext, tc) { message[0] = (id >> 8) & 0xff; message[1] = id & 0xff; - isc_socket_attach(dns_dispatch_getsocket(dispatch), &dsock); region.base = message; region.length = sizeof(message); - result = isc_socket_sendto(dsock, ®ion, task, senddone, dsock, - &local, NULL); + result = isc_app_onrun(mctx, task, startit, ®ion); ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); result = isc_app_run();