aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-05-08 14:09:38 -0400
committerNick Mathewson <nickm@torproject.org>2018-05-08 14:09:38 -0400
commit2a4439adf37ed75c8f7d2db3134d0263f70de796 (patch)
tree97e06f73e0a9940e171bfd47d9907cfbbaf96d4c /src/test
parentbf5eaa82da4214be681cf0674f24376b7c4c0e34 (diff)
parent6e3e96d2ff0c1b83bdd3f2059d1b4a2b96a53341 (diff)
downloadtor-2a4439adf37ed75c8f7d2db3134d0263f70de796.tar.gz
tor-2a4439adf37ed75c8f7d2db3134d0263f70de796.zip
Merge branch 'ticket26008'
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test_workqueue.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/test/test_workqueue.c b/src/test/test_workqueue.c
index 8d29d2062d..cc7073850c 100644
--- a/src/test/test_workqueue.c
+++ b/src/test/test_workqueue.c
@@ -224,7 +224,8 @@ add_n_work_items(threadpool_t *tp, int n)
workqueue_entry_t **to_cancel;
workqueue_entry_t *ent;
- to_cancel = tor_malloc(sizeof(workqueue_entry_t*) * opt_n_cancel);
+ // We'll choose randomly which entries to cancel.
+ to_cancel = tor_calloc(opt_n_cancel, sizeof(workqueue_entry_t*));
while (n_queued++ < n) {
ent = add_work(tp);
@@ -233,9 +234,14 @@ add_n_work_items(threadpool_t *tp, int n)
tor_libevent_exit_loop_after_delay(tor_libevent_get_base(), NULL);
return -1;
}
- if (n_try_cancel < opt_n_cancel &&
- tor_weak_random_range(&weak_rng, n) < opt_n_cancel) {
+
+ if (n_try_cancel < opt_n_cancel) {
to_cancel[n_try_cancel++] = ent;
+ } else {
+ int p = tor_weak_random_range(&weak_rng, n_queued);
+ if (p < n_try_cancel) {
+ to_cancel[p] = ent;
+ }
}
}