]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Prevent short TLS tests from hanging in case of errors
authorArtem Boldariev <artem@boldariev.com>
Tue, 6 Apr 2021 12:18:44 +0000 (15:18 +0300)
committerOndřej Surý <ondrej@sury.org>
Wed, 7 Apr 2021 13:36:59 +0000 (15:36 +0200)
The tests in tls_test.c could hang in the event of a connect
error.  This commit allows the tests to bail out when such an
error occurs.

lib/isc/tests/tls_test.c

index 9aaa899bcd7ef4adab7efee542060ecd20ec1cec..19f93fad3ddf9923fab473917517efbb3129953b 100644 (file)
@@ -75,6 +75,8 @@ static bool reuse_supported = true;
 static isc_tlsctx_t *server_tlsctx = NULL;
 static isc_tlsctx_t *client_tlsctx = NULL;
 
+static atomic_bool was_error = ATOMIC_VAR_INIT(false);
+
 #define NSENDS 100
 #define NWRITES 10
 
@@ -243,6 +245,8 @@ nm_setup(void **state) {
        atomic_store(&ctimeouts, 0);
        atomic_store(&cconnects, 0);
 
+       atomic_store(&was_error, false);
+
        isc_nonce_buf(&send_magic, sizeof(send_magic));
        isc_nonce_buf(&stop_magic, sizeof(stop_magic));
        if (send_magic == stop_magic) {
@@ -392,6 +396,7 @@ tls_connect_connect_cb(isc_nmhandle_t *handle, isc_result_t eresult,
        if (eresult != ISC_R_SUCCESS) {
                uint_fast64_t sends = atomic_load(&nsends);
                atomic_store(&slowdown, true);
+               atomic_store(&was_error, true);
 
                /* We failed to connect; try again */
                while (sends > 0) {
@@ -526,6 +531,9 @@ tls_recv_one(void **state) {
                          tls_connect_connect_cb, NULL, client_tlsctx, 1000, 0);
 
        while (atomic_load(&nsends) > 0) {
+               if (atomic_load(&was_error)) {
+                       break;
+               }
                isc_thread_yield();
        }
 
@@ -533,6 +541,9 @@ tls_recv_one(void **state) {
               atomic_load(&sreads) != 1 || atomic_load(&creads) != 0 ||
               atomic_load(&csends) != 1)
        {
+               if (atomic_load(&was_error)) {
+                       break;
+               }
                isc_thread_yield();
        }
 
@@ -581,12 +592,18 @@ tls_recv_two(void **state) {
                          0);
 
        while (atomic_load(&nsends) > 0) {
+               if (atomic_load(&was_error)) {
+                       break;
+               }
                isc_thread_yield();
        }
 
        while (atomic_load(&sreads) < 2 || atomic_load(&ssends) < 1 ||
               atomic_load(&csends) < 2 || atomic_load(&creads) < 1)
        {
+               if (atomic_load(&was_error)) {
+                       break;
+               }
                isc_thread_yield();
        }