aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_threads.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-09-13 20:47:41 -0400
committerNick Mathewson <nickm@torproject.org>2018-09-13 20:47:41 -0400
commit7a0ff5beb21e6485bda44c0545036bb2883f643d (patch)
tree44f2ed72bd6971da64a1d87666fb47c81acaec23 /src/test/test_threads.c
parentc02f2d9eb45786c552dcc33c102e9964d95f66c1 (diff)
downloadtor-7a0ff5beb21e6485bda44c0545036bb2883f643d.tar.gz
tor-7a0ff5beb21e6485bda44c0545036bb2883f643d.zip
In conditionvar_timeout test, wait for threads to timeout
Previously we just waited 200msec, which was not enough on slow/busy systems. Fixes bug 27073; bugfix on 0.2.6.3-alpha when the test was introduced.
Diffstat (limited to 'src/test/test_threads.c')
-rw-r--r--src/test/test_threads.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/test/test_threads.c b/src/test/test_threads.c
index ebbc95c7ca..448ab2034b 100644
--- a/src/test/test_threads.c
+++ b/src/test/test_threads.c
@@ -234,25 +234,33 @@ test_threads_conditionvar(void *arg)
if (timeout) {
ti->tv = &msec100;
}
+
+#define SPIN_UNTIL(condition,sleep_msec) \
+ while (1) { \
+ tor_mutex_acquire(ti->mutex); \
+ if (condition) { \
+ break; \
+ } \
+ tor_mutex_release(ti->mutex); \
+ tor_sleep_msec(sleep_msec); \
+ }
+
spawn_func(cv_test_thr_fn_, ti);
spawn_func(cv_test_thr_fn_, ti);
spawn_func(cv_test_thr_fn_, ti);
spawn_func(cv_test_thr_fn_, ti);
- tor_mutex_acquire(ti->mutex);
+ SPIN_UNTIL(ti->n_threads == 4, 10);
+
+ time_t started_at = time(NULL);
+
ti->addend = 7;
ti->shutdown = 1;
tor_cond_signal_one(ti->cond);
tor_mutex_release(ti->mutex);
#define SPIN() \
- while (1) { \
- tor_mutex_acquire(ti->mutex); \
- if (ti->addend == 0) { \
- break; \
- } \
- tor_mutex_release(ti->mutex); \
- }
+ SPIN_UNTIL(ti->addend == 0, 0)
SPIN();
@@ -279,8 +287,9 @@ test_threads_conditionvar(void *arg)
if (!timeout) {
tt_int_op(ti->n_shutdown, ==, 4);
} else {
- tor_sleep_msec(200);
- tor_mutex_acquire(ti->mutex);
+ const int GIVE_UP_AFTER_SEC = 30;
+ SPIN_UNTIL((ti->n_timeouts == 2 ||
+ time(NULL) >= started_at + GIVE_UP_AFTER_SEC), 10);
tt_int_op(ti->n_shutdown, ==, 2);
tt_int_op(ti->n_timeouts, ==, 2);
tor_mutex_release(ti->mutex);
@@ -301,4 +310,3 @@ struct testcase_t thread_tests[] = {
&passthrough_setup, (void*)"tv" },
END_OF_TESTCASES
};
-