diff options
Diffstat (limited to 'tests/t_workqueue.c')
| -rw-r--r-- | tests/t_workqueue.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/t_workqueue.c b/tests/t_workqueue.c index c454e5b..660d882 100644 --- a/tests/t_workqueue.c +++ b/tests/t_workqueue.c | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include <string.h> | 6 | #include <string.h> |
| 7 | 7 | ||
| 8 | /* Opentracker */ | 8 | /* Opentracker */ |
| 9 | #include "ot_fdstate.h" | ||
| 9 | #include "ot_workqueue.h" | 10 | #include "ot_workqueue.h" |
| 10 | #include "test.h" | 11 | #include "test.h" |
| 11 | 12 | ||
| @@ -96,10 +97,61 @@ static void case_cancelled_task_is_not_handed_out(void) { | |||
| 96 | workqueue_canceltask(48); | 97 | workqueue_canceltask(48); |
| 97 | } | 98 | } |
| 98 | 99 | ||
| 100 | /* Tasks are filed under a descriptor number, and the number is handed to the | ||
| 101 | next connection the moment this one closes. */ | ||
| 102 | |||
| 103 | static void case_cancel_takes_every_task_of_the_socket(void) { | ||
| 104 | ot_tasktype asked; | ||
| 105 | |||
| 106 | test_case("cancelling a socket leaves none of its tasks behind"); | ||
| 107 | CHECK_INT(workqueue_pushtask(49, TASK_FULLSCRAPE_TPB_ASCII), 0); | ||
| 108 | CHECK_INT(workqueue_pushtask(49, TASK_FULLSCRAPE_TPB_BINARY), 0); | ||
| 109 | CHECK_INT(workqueue_pushtask(50, TASK_FULLSCRAPE), 0); | ||
| 110 | workqueue_canceltask(49); | ||
| 111 | |||
| 112 | asked = TASK_FULLSCRAPE; | ||
| 113 | CHECK(workqueue_poptask(&asked) != 0); | ||
| 114 | CHECK_INT(asked, TASK_FULLSCRAPE); | ||
| 115 | workqueue_canceltask(50); | ||
| 116 | } | ||
| 117 | |||
| 118 | static void case_result_names_the_connection_that_asked(void) { | ||
| 119 | ot_tasktype asked = TASK_STATS; | ||
| 120 | ot_taskid taskid; | ||
| 121 | struct iovec *iovector; | ||
| 122 | size_t iovec_entries; | ||
| 123 | int is_partial; | ||
| 124 | uint32_t asked_under, answered_under = ~0u; | ||
| 125 | |||
| 126 | CHECK_INT(fdstate_init(), 0); | ||
| 127 | asked_under = fdstate_open(51, NULL, 0); | ||
| 128 | |||
| 129 | test_case("a result comes back with the generation its task was pushed under"); | ||
| 130 | CHECK_INT(workqueue_pushtask(51, TASK_STATS_PEERS), 0); | ||
| 131 | taskid = workqueue_poptask(&asked); | ||
| 132 | CHECK(taskid != 0); | ||
| 133 | |||
| 134 | /* The connection goes away without cancelling and the number is reused */ | ||
| 135 | fdstate_close(51); | ||
| 136 | fdstate_open(51, NULL, 0); | ||
| 137 | |||
| 138 | CHECK_INT(workqueue_pushresult(taskid, 0, NULL), 0); | ||
| 139 | CHECK_INT(workqueue_popresult(&iovec_entries, &iovector, &is_partial, &answered_under), 51); | ||
| 140 | CHECK_INT(answered_under, asked_under); | ||
| 141 | |||
| 142 | test_case("which is no longer the one the descriptor carries"); | ||
| 143 | CHECK(fdstate_generation(51) != answered_under); | ||
| 144 | |||
| 145 | fdstate_close(51); | ||
| 146 | fdstate_deinit(); | ||
| 147 | } | ||
| 148 | |||
| 99 | void test_workqueue(void) { | 149 | void test_workqueue(void) { |
| 100 | case_task_goes_to_its_own_class(); | 150 | case_task_goes_to_its_own_class(); |
| 101 | case_flags_survive_the_queue(); | 151 | case_flags_survive_the_queue(); |
| 102 | case_classes_do_not_cross(); | 152 | case_classes_do_not_cross(); |
| 103 | case_every_task_gets_its_own_id(); | 153 | case_every_task_gets_its_own_id(); |
| 104 | case_cancelled_task_is_not_handed_out(); | 154 | case_cancelled_task_is_not_handed_out(); |
| 155 | case_cancel_takes_every_task_of_the_socket(); | ||
| 156 | case_result_names_the_connection_that_asked(); | ||
| 105 | } | 157 | } |
