]> granicus.if.org Git - libevent/commitdiff
test/regress_ssl: cover case when server didn't up (failed with timeout)
authorAzat Khuzhin <a3at.mail@gmail.com>
Wed, 2 Sep 2015 14:36:20 +0000 (17:36 +0300)
committerAzat Khuzhin <a3at.mail@gmail.com>
Wed, 2 Sep 2015 16:08:36 +0000 (19:08 +0300)
test/regress_ssl.c

index 6896e8ece4c654a8be4de854a3d0f9efcf673c8e..628d56dd8f6a619d788781a9f214d09be1d60b6b 100644 (file)
@@ -178,6 +178,7 @@ static int test_is_done = 0;
 static int n_connected = 0;
 static int got_close = 0;
 static int got_error = 0;
+static int got_timeout = 0;
 static int renegotiate_at = -1;
 static int stop_when_connected = 0;
 static int pending_connect_events = 0;
@@ -196,6 +197,7 @@ enum regress_openssl_type
        REGRESS_OPENSSL_SERVER = 128,
 
        REGRESS_OPENSSL_FREED = 256,
+       REGRESS_OPENSSL_TIMEOUT = 512,
 };
 
 static void
@@ -311,6 +313,16 @@ eventcb(struct bufferevent *bev, short what, void *ctx)
                        bufferevent_openssl_check_freed(bev);
                }
                bufferevent_free(bev);
+       } else if (what & BEV_EVENT_TIMEOUT) {
+               TT_BLATHER(("Got timeout."));
+               ++got_timeout;
+               if (type & REGRESS_OPENSSL_FD) {
+                       bufferevent_openssl_check_fd(bev, type & REGRESS_OPENSSL_FILTER);
+               }
+               if (type & REGRESS_OPENSSL_FREED) {
+                       bufferevent_openssl_check_freed(bev);
+               }
+               bufferevent_free(bev);
        }
 end:
        ;
@@ -420,22 +432,43 @@ regress_bufferevent_openssl(void *arg)
                    fd_pair, bev_ll, type);
        }
 
-       bufferevent_enable(bev1, EV_READ|EV_WRITE);
-       bufferevent_enable(bev2, EV_READ|EV_WRITE);
+       if (!(type & REGRESS_OPENSSL_TIMEOUT)) {
+               bufferevent_enable(bev1, EV_READ|EV_WRITE);
+               bufferevent_enable(bev2, EV_READ|EV_WRITE);
 
-       evbuffer_add_printf(bufferevent_get_output(bev1), "1\n");
+               evbuffer_add_printf(bufferevent_get_output(bev1), "1\n");
 
-       event_base_dispatch(data->base);
+               event_base_dispatch(data->base);
 
-       tt_assert(test_is_done == 1);
-       tt_assert(n_connected == 2);
+               tt_assert(test_is_done == 1);
+               tt_assert(n_connected == 2);
 
-       /* We don't handle shutdown properly yet */
-       if (type & REGRESS_OPENSSL_DIRTY_SHUTDOWN) {
-               tt_int_op(got_close, ==, 1);
-               tt_int_op(got_error, ==, 0);
+               /* We don't handle shutdown properly yet */
+               if (type & REGRESS_OPENSSL_DIRTY_SHUTDOWN) {
+                       tt_int_op(got_close, ==, 1);
+                       tt_int_op(got_error, ==, 0);
+               } else {
+                       tt_int_op(got_error, ==, 1);
+               }
+               tt_int_op(got_timeout, ==, 0);
        } else {
-               tt_int_op(got_error, ==, 1);
+               struct timeval t = { 2 };
+
+               bufferevent_enable(bev1, EV_READ|EV_WRITE);
+               bufferevent_disable(bev2, EV_READ|EV_WRITE);
+
+               bufferevent_set_timeouts(bev1, &t, &t);
+
+               evbuffer_add_printf(bufferevent_get_output(bev1), "1\n");
+
+               event_base_dispatch(data->base);
+
+               tt_assert(test_is_done == 0);
+               tt_assert(n_connected == 0);
+
+               tt_int_op(got_close, ==, 0);
+               tt_int_op(got_error, ==, 0);
+               tt_int_op(got_timeout, ==, 1);
        }
 end:
        return;
@@ -577,6 +610,10 @@ struct testcase_t ssl_testcases[] = {
        { "bufferevent_filter_freed_fd", regress_bufferevent_openssl,
          TT_ISOLATED, &basic_setup,
          T(REGRESS_OPENSSL_FILTER | REGRESS_OPENSSL_FREED | REGRESS_OPENSSL_FD) },
+
+       { "bufferevent_socketpair_timeout", regress_bufferevent_openssl,
+         TT_ISOLATED, &basic_setup,
+         T(REGRESS_OPENSSL_SOCKETPAIR | REGRESS_OPENSSL_TIMEOUT) },
 #undef T
 
        { "bufferevent_connect", regress_bufferevent_openssl_connect,