From e8fe46d7ae497b08f8ae0cbdc812babc80c4f069 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Thu, 26 Sep 2024 14:52:59 -0700 Subject: [PATCH] fix thread related test/disable pipe tests --- source/darwin/dispatch_queue_event_loop.c | 5 +++-- tests/CMakeLists.txt | 10 +++++++--- tests/event_loop_test.c | 15 ++++++++++++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/source/darwin/dispatch_queue_event_loop.c b/source/darwin/dispatch_queue_event_loop.c index 9faf724f0..53b248297 100644 --- a/source/darwin/dispatch_queue_event_loop.c +++ b/source/darwin/dispatch_queue_event_loop.c @@ -241,12 +241,13 @@ static void s_destroy(struct aws_event_loop *event_loop) { /* cancel outstanding tasks */ dispatch_async_and_wait(dispatch_loop->dispatch_queue, ^{ - aws_task_scheduler_clean_up(&dispatch_loop->scheduler); - aws_mutex_lock(&dispatch_loop->synced_data.lock); dispatch_loop->synced_data.current_thread_id = aws_thread_current_thread_id(); dispatch_loop->synced_data.is_executing = true; aws_mutex_unlock(&dispatch_loop->synced_data.lock); + + aws_task_scheduler_clean_up(&dispatch_loop->scheduler); + while (!aws_linked_list_empty(&dispatch_loop->synced_data.cross_thread_tasks)) { struct aws_linked_list_node *node = aws_linked_list_pop_front(&dispatch_loop->synced_data.cross_thread_tasks); struct aws_task *task = AWS_CONTAINER_OF(node, struct aws_task, node); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a222e3ec2..c4db357ec 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -17,6 +17,8 @@ endmacro() add_test_case(io_library_init) add_test_case(io_library_init_cleanup_init_cleanup) +# DEBUG: temporarily disable the pipe related tests +if(NOT AWS_USE_DISPATCH_QUEUE) add_pipe_test_case(pipe_open_close) add_pipe_test_case(pipe_read_write) add_pipe_test_case(pipe_read_write_large_buffer) @@ -29,13 +31,15 @@ add_pipe_test_case(pipe_error_event_sent_after_write_end_closed) add_pipe_test_case(pipe_error_event_sent_on_subscribe_if_write_end_already_closed) add_pipe_test_case(pipe_writes_are_fifo) add_pipe_test_case(pipe_clean_up_cancels_pending_writes) +endif() + add_test_case(event_loop_xthread_scheduled_tasks_execute) add_test_case(event_loop_canceled_tasks_run_in_el_thread) if(USE_IO_COMPLETION_PORTS) add_test_case(event_loop_completion_events) -else() +elseif(NOT AWS_USE_DISPATCH_QUEUE) # TODO: setup a test for dispatch queue once pipe is there. add_test_case(event_loop_subscribe_unsubscribe) add_test_case(event_loop_writable_event_on_subscribe) add_test_case(event_loop_no_readable_event_before_write) @@ -48,8 +52,7 @@ endif() add_test_case(event_loop_stop_then_restart) add_test_case(event_loop_multiple_stops) add_test_case(event_loop_group_setup_and_shutdown) -# DEBUG WIP CURRENTLY FAILS -# add_test_case(event_loop_group_setup_and_shutdown_async) +add_test_case(event_loop_group_setup_and_shutdown_async) add_test_case(numa_aware_event_loop_group_setup_and_shutdown) add_test_case(io_testing_channel) @@ -63,6 +66,7 @@ add_test_case(udp_bind_connect_communication) add_net_test_case(connect_timeout) add_net_test_case(connect_timeout_cancelation) + if(USE_VSOCK) add_test_case(vsock_loopback_socket_communication) endif() diff --git a/tests/event_loop_test.c b/tests/event_loop_test.c index 659f313c6..4722addfc 100644 --- a/tests/event_loop_test.c +++ b/tests/event_loop_test.c @@ -85,7 +85,11 @@ static int s_test_event_loop_xthread_scheduled_tasks_execute(struct aws_allocato ASSERT_TRUE(task_args.invoked); aws_mutex_unlock(&task_args.mutex); +// The dispatch queue will schedule tasks on thread pools, it is unpredicatable which thread we run the task on, +// therefore we do not validate the thread id for disaptch queue. +#ifndef AWS_USE_DISPATCH_QUEUE ASSERT_FALSE(aws_thread_thread_id_equal(task_args.thread_id, aws_thread_current_thread_id())); +#endif /* Test "now" tasks */ task_args.invoked = false; @@ -156,7 +160,7 @@ static int s_test_event_loop_canceled_tasks_run_in_el_thread(struct aws_allocato aws_event_loop_schedule_task_now(event_loop, &task1); uint64_t now; ASSERT_SUCCESS(aws_event_loop_current_clock_time(event_loop, &now)); - aws_event_loop_schedule_task_future(event_loop, &task2, now + 10000000000); + aws_event_loop_schedule_task_future(event_loop, &task2, now + 1000000000000); ASSERT_FALSE(aws_event_loop_thread_is_callers_thread(event_loop)); @@ -165,7 +169,12 @@ static int s_test_event_loop_canceled_tasks_run_in_el_thread(struct aws_allocato &task1_args.condition_variable, &task1_args.mutex, s_task_ran_predicate, &task1_args)); ASSERT_TRUE(task1_args.invoked); ASSERT_TRUE(task1_args.was_in_thread); + +// The dispatch queue will schedule tasks on thread pools, it is unpredicatable which thread we run the task on, +// therefore we do not validate the thread id for disaptch queue. +#ifndef AWS_USE_DISPATCH_QUEUE ASSERT_FALSE(aws_thread_thread_id_equal(task1_args.thread_id, aws_thread_current_thread_id())); +#endif ASSERT_INT_EQUALS(AWS_TASK_STATUS_RUN_READY, task1_args.status); aws_mutex_unlock(&task1_args.mutex); @@ -179,7 +188,11 @@ static int s_test_event_loop_canceled_tasks_run_in_el_thread(struct aws_allocato aws_mutex_unlock(&task2_args.mutex); ASSERT_TRUE(task2_args.was_in_thread); +// The dispatch queue will schedule tasks on thread pools, it is unpredicatable which thread we run the task on, +// therefore we do not validate the thread id for disaptch queue. +#ifndef AWS_USE_DISPATCH_QUEUE ASSERT_TRUE(aws_thread_thread_id_equal(task2_args.thread_id, aws_thread_current_thread_id())); +#endif ASSERT_INT_EQUALS(AWS_TASK_STATUS_CANCELED, task2_args.status); }