diff --git a/test/test-list.h b/test/test-list.h index 0d385f21..78ff9c2d 100644 --- a/test/test-list.h +++ b/test/test-list.h @@ -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) diff --git a/test/test-threadpool-cancel.c b/test/test-threadpool-cancel.c index 07634e3f..fed0b07a 100644 --- a/test/test-threadpool-cancel.c +++ b/test/test-threadpool-cancel.c @@ -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; +}