test: add uv_cancel test for threadpool (#4065 2/2)
Check that uv_cancel() returns UV_EBUSY when called while the uv_work_cb is being executed.
This commit is contained in:
parent
3e0b846bdb
commit
6df5a72151
@ -454,6 +454,7 @@ TEST_DECLARE (threadpool_cancel_random)
|
||||
TEST_DECLARE (threadpool_cancel_work)
|
||||
TEST_DECLARE (threadpool_cancel_fs)
|
||||
TEST_DECLARE (threadpool_cancel_single)
|
||||
TEST_DECLARE (threadpool_cancel_when_busy)
|
||||
TEST_DECLARE (thread_local_storage)
|
||||
TEST_DECLARE (thread_stack_size)
|
||||
TEST_DECLARE (thread_stack_size_explicit)
|
||||
@ -1143,6 +1144,7 @@ TASK_LIST_START
|
||||
TEST_ENTRY (threadpool_cancel_work)
|
||||
TEST_ENTRY (threadpool_cancel_fs)
|
||||
TEST_ENTRY (threadpool_cancel_single)
|
||||
TEST_ENTRY (threadpool_cancel_when_busy)
|
||||
TEST_ENTRY (thread_local_storage)
|
||||
TEST_ENTRY (thread_stack_size)
|
||||
TEST_ENTRY (thread_stack_size_explicit)
|
||||
|
||||
@ -378,3 +378,36 @@ TEST_IMPL(threadpool_cancel_single) {
|
||||
MAKE_VALGRIND_HAPPY(loop);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void after_busy_cb(uv_work_t* req, int status) {
|
||||
ASSERT_OK(status);
|
||||
done_cb_called++;
|
||||
}
|
||||
|
||||
static void busy_cb(uv_work_t* req) {
|
||||
uv_sem_post((uv_sem_t*) req->data);
|
||||
/* Assume that calling uv_cancel() takes less than 10ms. */
|
||||
uv_sleep(10);
|
||||
}
|
||||
|
||||
TEST_IMPL(threadpool_cancel_when_busy) {
|
||||
uv_sem_t sem_lock;
|
||||
uv_work_t req;
|
||||
|
||||
req.data = &sem_lock;
|
||||
|
||||
ASSERT_OK(uv_sem_init(&sem_lock, 0));
|
||||
ASSERT_OK(uv_queue_work(uv_default_loop(), &req, busy_cb, after_busy_cb));
|
||||
|
||||
uv_sem_wait(&sem_lock);
|
||||
|
||||
ASSERT_EQ(uv_cancel((uv_req_t*) &req), UV_EBUSY);
|
||||
ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT));
|
||||
ASSERT_EQ(done_cb_called, 1);
|
||||
|
||||
uv_sem_destroy(&sem_lock);
|
||||
|
||||
MAKE_VALGRIND_HAPPY(uv_default_loop());
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user