Skip to content

Commit

Permalink
fix thread related test/disable pipe tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xiazhvera committed Sep 26, 2024
1 parent ed04764 commit e8fe46d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
5 changes: 3 additions & 2 deletions source/darwin/dispatch_queue_event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 7 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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()
Expand Down
15 changes: 14 additions & 1 deletion tests/event_loop_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));

Expand All @@ -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);

Expand All @@ -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);
}

Expand Down

0 comments on commit e8fe46d

Please sign in to comment.