]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Retry on timeout in the UDP recv_one, recv_two and double_read tests
authorOndřej Surý <ondrej@isc.org>
Wed, 12 Oct 2022 07:43:56 +0000 (09:43 +0200)
committerOndřej Surý <ondrej@isc.org>
Wed, 12 Oct 2022 13:33:58 +0000 (15:33 +0200)
Since we are testing UDP on the localhost and the same interface, the
UDP datagrams can't get lost.  Change the connect read callback, so it
starts reading again on the timeout instead of just getting stuck, and
fail when any other result codes than ISC_R_SUCCESS and ISC_R_TIMEDOUT
are received because we don't expect them to happen in these simple
tests.

tests/isc/udp_test.c

index c36074e3041f7dba039ead7ef47fc0bd13aeceaf..1006caa4d16abfa04f2105636c5fd0878dd390cb 100644 (file)
@@ -806,6 +806,52 @@ udp__connect(void *arg __attribute__((__unused__))) {
                          udp__connect_cb, NULL, T_CONNECT);
 }
 
+static void
+udp__connect_read_cb(isc_nmhandle_t *handle, isc_result_t eresult,
+                    isc_region_t *region, void *cbarg) {
+       uint64_t magic = 0;
+
+       assert_non_null(handle);
+
+       F();
+
+       switch (eresult) {
+       case ISC_R_TIMEDOUT:
+               /*
+                * We are operating on the localhost, UDP cannot get lost, but
+                * it could be delayed, so we read again until we get the
+                * answer.
+                */
+               isc_nm_read(handle, connect_readcb, cbarg);
+               return;
+       case ISC_R_SUCCESS:
+               assert_true(region->length >= sizeof(magic));
+
+               memmove(&magic, region->base, sizeof(magic));
+
+               assert_true(magic == send_magic);
+
+               if (have_expected_creads(atomic_fetch_add(&creads, 1) + 1)) {
+                       do_creads_shutdown(loopmgr);
+               }
+
+               if (magic == send_magic && allow_send_back) {
+                       connect_send(handle);
+                       return;
+               }
+
+               break;
+       default:
+               fprintf(stderr, "%s(%p, %s, %p)\n", __func__, handle,
+                       isc_result_totext(eresult), cbarg);
+               assert_int_equal(eresult, ISC_R_SUCCESS);
+       }
+
+       isc_refcount_decrement(&active_creads);
+
+       isc_nmhandle_detach(&handle);
+}
+
 static void
 udp__connect_cb(isc_nmhandle_t *handle, isc_result_t eresult, void *cbarg) {
        isc_nmhandle_t *readhandle = NULL;
@@ -853,6 +899,8 @@ udp__connect_cb(isc_nmhandle_t *handle, isc_result_t eresult, void *cbarg) {
 ISC_SETUP_TEST_IMPL(udp_recv_one) {
        setup_test(state);
 
+       connect_readcb = udp__connect_read_cb;
+
        expected_cconnects = 1;
        cconnects_shutdown = false;
 
@@ -892,6 +940,8 @@ ISC_LOOP_TEST_IMPL(udp_recv_one) {
 ISC_SETUP_TEST_IMPL(udp_recv_two) {
        setup_test(state);
 
+       connect_readcb = udp__connect_read_cb;
+
        expected_cconnects = 2;
        cconnects_shutdown = false;
 
@@ -1044,6 +1094,14 @@ double_read_cb(isc_nmhandle_t *handle, isc_result_t eresult,
        F();
 
        switch (eresult) {
+       case ISC_R_TIMEDOUT:
+               /*
+                * We are operating on the localhost, UDP cannot get lost, but
+                * it could be delayed, so we read again until we get the
+                * answer.
+                */
+               detach = false;
+               break;
        case ISC_R_SUCCESS:
                assert_true(region->length >= sizeof(magic));
 
@@ -1062,7 +1120,6 @@ double_read_cb(isc_nmhandle_t *handle, isc_result_t eresult,
                }
 
                break;
-       case ISC_R_TIMEDOUT:
        case ISC_R_EOF:
        case ISC_R_SHUTTINGDOWN:
        case ISC_R_CANCELED: