diff options
author | Sebastian Hahn <sebastian@torproject.org> | 2015-08-20 19:57:08 +0200 |
---|---|---|
committer | Sebastian Hahn <sebastian@torproject.org> | 2015-08-20 20:00:05 +0200 |
commit | 2657ea802bd9633aeea8774b32d64ed671624818 (patch) | |
tree | 58976fd5c843709880b08c2d2057763330eb0803 /src/test/test_workqueue.c | |
parent | 428bb2d1c8bf5f10f7f76b9861b9a3ce498e07a7 (diff) | |
download | tor-2657ea802bd9633aeea8774b32d64ed671624818.tar.gz tor-2657ea802bd9633aeea8774b32d64ed671624818.zip |
New testcase exposing bug during threadpool shutdown
We don't want to accept any work after one of our worker functions has
returned WQ_RPL_SHUTDOWN. This testcase currently fails, because we do
not actually stop any of the worker threads.
Diffstat (limited to 'src/test/test_workqueue.c')
-rw-r--r-- | src/test/test_workqueue.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/test/test_workqueue.c b/src/test/test_workqueue.c index 7f20642041..1d2cd940c3 100644 --- a/src/test/test_workqueue.c +++ b/src/test/test_workqueue.c @@ -124,6 +124,14 @@ workqueue_do_ecdh(void *state, void *work) return WQ_RPL_REPLY; } +static int +workqueue_shutdown_error(void *state, void *work) +{ + (void)state; + (void)work; + return WQ_RPL_REPLY; +} + static void * new_state(void *arg) { @@ -156,6 +164,7 @@ static int n_sent = 0; static int rsa_sent = 0; static int ecdh_sent = 0; static int n_received = 0; +static int no_shutdown = 0; #ifdef TRACK_RESPONSES bitarray_t *received; @@ -174,6 +183,14 @@ handle_reply(void *arg) ++n_received; } +/* This should never get called. */ +static void +handle_reply_shutdown(void *arg) +{ + (void)arg; + no_shutdown = 1; +} + static workqueue_entry_t * add_work(threadpool_t *tp) { @@ -288,6 +305,8 @@ replysock_readable_cb(tor_socket_t sock, short what, void *arg) shutting_down = 1; threadpool_queue_update(tp, NULL, workqueue_do_shutdown, NULL, NULL); + // Anything we add after starting the shutdown must not be executed. + threadpool_queue_work(tp, workqueue_shutdown_error, handle_reply_shutdown, NULL); { struct timeval limit = { 2, 0 }; tor_event_base_loopexit(tor_libevent_get_base(), &limit); @@ -416,6 +435,9 @@ main(int argc, char **argv) printf("%d+%d vs %d\n", n_received, n_successful_cancel, n_sent); puts("FAIL"); return 1; + } else if (no_shutdown) { + puts("Accepted work after shutdown\n"); + puts("FAIL"); } else { puts("OK"); return 0; |