@@ -80,6 +80,8 @@ static int s_tester_init(struct tester *tester, struct aws_allocator *alloc) {
8080
8181 aws_channel_acquire_hold (tester -> testing_channel .channel );
8282
83+ testing_channel_drain_queued_tasks (& tester -> testing_channel );
84+
8385 return AWS_OP_SUCCESS ;
8486}
8587
@@ -150,7 +152,7 @@ H1_CLIENT_TEST_CASE(h1_client_request_send_1liner) {
150152 struct aws_http_stream * stream = aws_http_stream_new_client_request (& opt );
151153 ASSERT_NOT_NULL (stream );
152154
153- testing_channel_execute_queued_tasks (& tester .testing_channel );
155+ testing_channel_drain_queued_tasks (& tester .testing_channel );
154156
155157 /* check result */
156158 const char * expected = "GET / HTTP/1.1\r\n"
@@ -190,7 +192,7 @@ H1_CLIENT_TEST_CASE(h1_client_request_send_headers) {
190192 struct aws_http_stream * stream = aws_http_stream_new_client_request (& opt );
191193 ASSERT_NOT_NULL (stream );
192194
193- testing_channel_execute_queued_tasks (& tester .testing_channel );
195+ testing_channel_drain_queued_tasks (& tester .testing_channel );
194196
195197 /* check result */
196198 const char * expected = "GET / HTTP/1.1\r\n"
@@ -255,7 +257,7 @@ H1_CLIENT_TEST_CASE(h1_client_request_send_body) {
255257 struct aws_http_stream * stream = aws_http_stream_new_client_request (& opt );
256258 ASSERT_NOT_NULL (stream );
257259
258- testing_channel_execute_queued_tasks (& tester .testing_channel );
260+ testing_channel_drain_queued_tasks (& tester .testing_channel );
259261
260262 /* check result */
261263 const char * expected = "PUT /plan.txt HTTP/1.1\r\n"
@@ -290,7 +292,7 @@ static int s_check_multiple_messages(struct tester *tester, struct aws_byte_curs
290292 while (remaining > 0 ) {
291293 /* Tick event loop if there are no messages already */
292294 if (aws_linked_list_empty (msgs )) {
293- testing_channel_execute_queued_tasks (& tester -> testing_channel );
295+ testing_channel_run_currently_queued_tasks (& tester -> testing_channel );
294296 }
295297
296298 /* There should be EXACTLY 1 aws_io_message after ticking. */
@@ -317,7 +319,7 @@ static int s_check_multiple_messages(struct tester *tester, struct aws_byte_curs
317319 }
318320
319321 /* Check that no more messages are produced unexpectedly */
320- testing_channel_execute_queued_tasks (& tester -> testing_channel );
322+ testing_channel_drain_queued_tasks (& tester -> testing_channel );
321323 ASSERT_TRUE (aws_linked_list_empty (msgs ));
322324
323325 * out_num_messages = num_messages ;
@@ -470,7 +472,7 @@ H1_CLIENT_TEST_CASE(h1_client_request_send_multiple_in_1_io_message) {
470472 ASSERT_NOT_NULL (streams [i ]);
471473 }
472474
473- testing_channel_execute_queued_tasks (& tester .testing_channel );
475+ testing_channel_drain_queued_tasks (& tester .testing_channel );
474476
475477 /* check result */
476478 const char * expected = "GET / HTTP/1.1\r\n"
@@ -676,11 +678,13 @@ H1_CLIENT_TEST_CASE(h1_client_response_get_1liner) {
676678 struct response_tester response ;
677679 ASSERT_SUCCESS (s_response_tester_init (& response , allocator , & opt ));
678680
679- testing_channel_execute_queued_tasks (& tester .testing_channel );
681+ testing_channel_drain_queued_tasks (& tester .testing_channel );
680682
681683 /* send response */
682684 ASSERT_SUCCESS (s_send_response_str (& tester , "HTTP/1.1 204 No Content\r\n\r\n" ));
683685
686+ testing_channel_drain_queued_tasks (& tester .testing_channel );
687+
684688 /* check result */
685689 ASSERT_TRUE (response .on_complete_cb_count == 1 );
686690 ASSERT_TRUE (response .on_complete_error_code == AWS_ERROR_SUCCESS );
@@ -719,7 +723,7 @@ H1_CLIENT_TEST_CASE(h1_client_response_get_headers) {
719723 struct response_tester response ;
720724 ASSERT_SUCCESS (s_response_tester_init (& response , allocator , & opt ));
721725
722- testing_channel_execute_queued_tasks (& tester .testing_channel );
726+ testing_channel_drain_queued_tasks (& tester .testing_channel );
723727
724728 /* send response */
725729 ASSERT_SUCCESS (s_send_response_str (
@@ -729,6 +733,8 @@ H1_CLIENT_TEST_CASE(h1_client_response_get_headers) {
729733 "Location: /index.html\r\n"
730734 "\r\n" ));
731735
736+ testing_channel_drain_queued_tasks (& tester .testing_channel );
737+
732738 /* check result */
733739 ASSERT_TRUE (response .on_complete_cb_count == 1 );
734740 ASSERT_TRUE (response .on_complete_error_code == AWS_ERROR_SUCCESS );
@@ -759,7 +765,7 @@ H1_CLIENT_TEST_CASE(h1_client_response_get_body) {
759765 struct response_tester response ;
760766 ASSERT_SUCCESS (s_response_tester_init (& response , allocator , & opt ));
761767
762- testing_channel_execute_queued_tasks (& tester .testing_channel );
768+ testing_channel_drain_queued_tasks (& tester .testing_channel );
763769
764770 /* send response */
765771 ASSERT_SUCCESS (s_send_response_str (
@@ -769,6 +775,8 @@ H1_CLIENT_TEST_CASE(h1_client_response_get_body) {
769775 "\r\n"
770776 "Call Momo" ));
771777
778+ testing_channel_drain_queued_tasks (& tester .testing_channel );
779+
772780 /* check result */
773781 ASSERT_TRUE (response .on_complete_cb_count == 1 );
774782 ASSERT_TRUE (response .on_complete_error_code == AWS_ERROR_SUCCESS );
@@ -799,7 +807,7 @@ H1_CLIENT_TEST_CASE(h1_client_response_get_1_from_multiple_io_messages) {
799807 struct response_tester response ;
800808 ASSERT_SUCCESS (s_response_tester_init (& response , allocator , & opt ));
801809
802- testing_channel_execute_queued_tasks (& tester .testing_channel );
810+ testing_channel_drain_queued_tasks (& tester .testing_channel );
803811
804812 /* send response with each byte in its own aws_io_message */
805813 const char * response_str = "HTTP/1.1 200 OK\r\n"
@@ -811,6 +819,8 @@ H1_CLIENT_TEST_CASE(h1_client_response_get_1_from_multiple_io_messages) {
811819 s_send_response (& tester , aws_byte_cursor_from_array (response_str + i , 1 ));
812820 }
813821
822+ testing_channel_drain_queued_tasks (& tester .testing_channel );
823+
814824 /* check result */
815825 ASSERT_TRUE (response .on_complete_cb_count == 1 );
816826 ASSERT_TRUE (response .on_complete_error_code == AWS_ERROR_SUCCESS );
@@ -841,9 +851,8 @@ H1_CLIENT_TEST_CASE(h1_client_response_get_multiple_from_1_io_message) {
841851 struct response_tester responses [3 ];
842852 for (size_t i = 0 ; i < AWS_ARRAY_SIZE (responses ); ++ i ) {
843853 ASSERT_SUCCESS (s_response_tester_init (& responses [i ], allocator , & opt ));
844-
845- testing_channel_execute_queued_tasks (& tester .testing_channel );
846854 }
855+ testing_channel_drain_queued_tasks (& tester .testing_channel );
847856
848857 /* send all responses in a single aws_io_message */
849858 ASSERT_SUCCESS (s_send_response_str (
@@ -852,6 +861,8 @@ H1_CLIENT_TEST_CASE(h1_client_response_get_multiple_from_1_io_message) {
852861 "HTTP/1.1 204 No Content\r\n\r\n"
853862 "HTTP/1.1 204 No Content\r\n\r\n" ));
854863
864+ testing_channel_drain_queued_tasks (& tester .testing_channel );
865+
855866 /* check results */
856867 for (size_t i = 0 ; i < AWS_ARRAY_SIZE (responses ); ++ i ) {
857868 ASSERT_TRUE (responses [i ].on_complete_cb_count == 1 );
@@ -882,12 +893,12 @@ H1_CLIENT_TEST_CASE(h1_client_response_with_bad_data_shuts_down_connection) {
882893 struct response_tester response ;
883894 ASSERT_SUCCESS (s_response_tester_init (& response , allocator , & opt ));
884895
885- testing_channel_execute_queued_tasks (& tester .testing_channel );
896+ testing_channel_drain_queued_tasks (& tester .testing_channel );
886897
887898 /* send response */
888899 ASSERT_SUCCESS (s_send_response_str_ignore_errors (& tester , "Mmmm garbage data\r\n\r\n" ));
889900
890- testing_channel_execute_queued_tasks (& tester .testing_channel );
901+ testing_channel_drain_queued_tasks (& tester .testing_channel );
891902
892903 /* check result */
893904 ASSERT_TRUE (response .on_complete_cb_count == 1 );
@@ -914,7 +925,7 @@ H1_CLIENT_TEST_CASE(h1_client_response_with_too_much_data_shuts_down_connection)
914925
915926 struct response_tester response ;
916927 ASSERT_SUCCESS (s_response_tester_init (& response , allocator , & opt ));
917- testing_channel_execute_queued_tasks (& tester .testing_channel );
928+ testing_channel_drain_queued_tasks (& tester .testing_channel );
918929
919930 /* send 2 responses in a single aws_io_message. */
920931 ASSERT_SUCCESS (s_send_response_ex (
@@ -923,6 +934,8 @@ H1_CLIENT_TEST_CASE(h1_client_response_with_too_much_data_shuts_down_connection)
923934 "HTTP/1.1 204 No Content\r\n\r\n" ),
924935 true /* ignore send errors */ ));
925936
937+ testing_channel_drain_queued_tasks (& tester .testing_channel );
938+
926939 /* 1st response should have come across successfully */
927940 ASSERT_TRUE (response .on_complete_cb_count == 1 );
928941 ASSERT_TRUE (response .on_complete_error_code == AWS_ERROR_SUCCESS );
@@ -933,7 +946,7 @@ H1_CLIENT_TEST_CASE(h1_client_response_with_too_much_data_shuts_down_connection)
933946 ASSERT_SUCCESS (s_response_tester_clean_up (& response ));
934947
935948 /* extra data should have caused channel shutdown */
936- testing_channel_execute_queued_tasks (& tester .testing_channel );
949+ testing_channel_drain_queued_tasks (& tester .testing_channel );
937950 ASSERT_TRUE (tester .is_shut_down );
938951 ASSERT_TRUE (tester .shutdown_error_code != AWS_ERROR_SUCCESS );
939952
@@ -1009,14 +1022,17 @@ H1_CLIENT_TEST_CASE(h1_client_response_arrives_before_request_done_sending_is_ok
10091022 ASSERT_SUCCESS (s_response_tester_init_ex (& response , allocator , & opt , & body_sender ));
10101023
10111024 /* send head of request */
1012- testing_channel_execute_queued_tasks (& tester .testing_channel );
1025+ testing_channel_run_currently_queued_tasks (& tester .testing_channel );
10131026
10141027 /* send response */
10151028 ASSERT_SUCCESS (s_send_response_str (& tester , "HTTP/1.1 200 OK\r\n\r\n" ));
10161029
10171030 /* tick loop until body finishes sending.*/
10181031 while (body_sender .cursor .len > 0 ) {
1019- testing_channel_execute_queued_tasks (& tester .testing_channel );
1032+ /* on_complete shouldn't fire until all outgoing data sent AND all incoming data received */
1033+ ASSERT_TRUE (response .on_complete_cb_count == 0 );
1034+
1035+ testing_channel_run_currently_queued_tasks (& tester .testing_channel );
10201036 }
10211037
10221038 /* check result */
@@ -1046,7 +1062,7 @@ H1_CLIENT_TEST_CASE(h1_client_response_without_request_shuts_down_connection) {
10461062 ASSERT_SUCCESS (s_tester_init (& tester , allocator ));
10471063
10481064 ASSERT_SUCCESS (s_send_response_str_ignore_errors (& tester , "HTTP/1.1 200 OK\r\n\r\n" ));
1049- testing_channel_execute_queued_tasks (& tester .testing_channel );
1065+ testing_channel_drain_queued_tasks (& tester .testing_channel );
10501066
10511067 ASSERT_TRUE (tester .is_shut_down );
10521068 ASSERT_TRUE (tester .shutdown_error_code != AWS_ERROR_SUCCESS );
@@ -1071,7 +1087,7 @@ H1_CLIENT_TEST_CASE(h1_client_window_reopens_by_default) {
10711087 struct response_tester response ;
10721088 ASSERT_SUCCESS (s_response_tester_init (& response , allocator , & opt ));
10731089
1074- testing_channel_execute_queued_tasks (& tester .testing_channel );
1090+ testing_channel_drain_queued_tasks (& tester .testing_channel );
10751091
10761092 /* send response */
10771093 const char * response_str = "HTTP/1.1 200 OK\r\n"
@@ -1080,6 +1096,8 @@ H1_CLIENT_TEST_CASE(h1_client_window_reopens_by_default) {
10801096 "Call Momo" ;
10811097 ASSERT_SUCCESS (s_send_response_str (& tester , response_str ));
10821098
1099+ testing_channel_drain_queued_tasks (& tester .testing_channel );
1100+
10831101 /* check result */
10841102 size_t window_update = testing_channel_last_window_update (& tester .testing_channel );
10851103 ASSERT_TRUE (window_update == strlen (response_str ));
@@ -1106,7 +1124,7 @@ H1_CLIENT_TEST_CASE(h1_client_window_shrinks_if_user_says_so) {
11061124 ASSERT_SUCCESS (s_response_tester_init (& response , allocator , & opt ));
11071125 response .stop_auto_window_update = true;
11081126
1109- testing_channel_execute_queued_tasks (& tester .testing_channel );
1127+ testing_channel_drain_queued_tasks (& tester .testing_channel );
11101128
11111129 /* send response */
11121130 const char * response_str = "HTTP/1.1 200 OK\r\n"
@@ -1115,6 +1133,8 @@ H1_CLIENT_TEST_CASE(h1_client_window_shrinks_if_user_says_so) {
11151133 "Call Momo" ;
11161134 ASSERT_SUCCESS (s_send_response_str (& tester , response_str ));
11171135
1136+ testing_channel_drain_queued_tasks (& tester .testing_channel );
1137+
11181138 /* check result */
11191139 size_t window_update = testing_channel_last_window_update (& tester .testing_channel );
11201140 size_t message_sans_body = strlen (response_str ) - 9 ;
@@ -1141,7 +1161,7 @@ static int s_window_update(struct aws_allocator *allocator, bool on_thread) {
11411161 ASSERT_SUCCESS (s_response_tester_init (& response , allocator , & opt ));
11421162 response .stop_auto_window_update = true;
11431163
1144- testing_channel_execute_queued_tasks (& tester .testing_channel );
1164+ testing_channel_drain_queued_tasks (& tester .testing_channel );
11451165
11461166 /* send response */
11471167 const char * response_str = "HTTP/1.1 200 OK\r\n"
@@ -1151,7 +1171,7 @@ static int s_window_update(struct aws_allocator *allocator, bool on_thread) {
11511171 ASSERT_SUCCESS (s_send_response_str (& tester , response_str ));
11521172
11531173 /* drain the task queue, in case there's an update window task in there from the headers */
1154- testing_channel_execute_queued_tasks (& tester .testing_channel );
1174+ testing_channel_drain_queued_tasks (& tester .testing_channel );
11551175
11561176 /* check result */
11571177 if (!on_thread ) {
@@ -1162,9 +1182,9 @@ static int s_window_update(struct aws_allocator *allocator, bool on_thread) {
11621182
11631183 if (!on_thread ) {
11641184 testing_channel_set_is_on_users_thread (& tester .testing_channel , true);
1165- testing_channel_execute_queued_tasks (& tester .testing_channel );
11661185 }
1167- testing_channel_execute_queued_tasks (& tester .testing_channel );
1186+
1187+ testing_channel_drain_queued_tasks (& tester .testing_channel );
11681188
11691189 size_t window_update = testing_channel_last_window_update (& tester .testing_channel );
11701190 ASSERT_INT_EQUALS (9 , window_update );
@@ -1208,11 +1228,11 @@ H1_CLIENT_TEST_CASE(h1_client_request_cancelled_by_channel_shutdown) {
12081228 struct aws_http_stream * stream = aws_http_stream_new_client_request (& opt );
12091229 ASSERT_NOT_NULL (stream );
12101230
1211- testing_channel_execute_queued_tasks (& tester .testing_channel );
1231+ testing_channel_drain_queued_tasks (& tester .testing_channel );
12121232
12131233 /* shutdown channel before request completes */
12141234 aws_channel_shutdown (tester .testing_channel .channel , AWS_ERROR_SUCCESS );
1215- testing_channel_execute_queued_tasks (& tester .testing_channel );
1235+ testing_channel_drain_queued_tasks (& tester .testing_channel );
12161236
12171237 /* even though the channel shut down with error_code 0,
12181238 * the stream should not get code 0 because it did not complete successfully */
@@ -1247,7 +1267,7 @@ H1_CLIENT_TEST_CASE(h1_client_multiple_requests_cancelled_by_channel_shutdown) {
12471267 }
12481268
12491269 /* 2 streams are now in-progress */
1250- testing_channel_execute_queued_tasks (& tester .testing_channel );
1270+ testing_channel_drain_queued_tasks (& tester .testing_channel );
12511271
12521272 /* Make 1 more stream that's still locked away in the pending queue */
12531273 opt .user_data = & completion_error_codes [2 ];
@@ -1256,7 +1276,7 @@ H1_CLIENT_TEST_CASE(h1_client_multiple_requests_cancelled_by_channel_shutdown) {
12561276
12571277 /* shutdown channel */
12581278 aws_channel_shutdown (tester .testing_channel .channel , AWS_ERROR_SUCCESS );
1259- testing_channel_execute_queued_tasks (& tester .testing_channel );
1279+ testing_channel_drain_queued_tasks (& tester .testing_channel );
12601280
12611281 /* check results */
12621282 for (int i = 0 ; i < 3 ; ++ i ) {
@@ -1379,7 +1399,6 @@ static void s_close_from_stream_complete(struct aws_http_stream *stream, int err
13791399static int s_test_close_from_callback (struct aws_allocator * allocator , enum request_callback close_at ) {
13801400 struct tester tester ;
13811401 ASSERT_SUCCESS (s_tester_init (& tester , allocator ));
1382- testing_channel_execute_queued_tasks (& tester .testing_channel );
13831402
13841403 struct close_from_callback_tester close_tester = {
13851404 .close_at = close_at ,
@@ -1409,7 +1428,7 @@ static int s_test_close_from_callback(struct aws_allocator *allocator, enum requ
14091428 struct aws_http_stream * stream = aws_http_stream_new_client_request (& opt );
14101429 ASSERT_NOT_NULL (stream );
14111430
1412- testing_channel_execute_queued_tasks (& tester .testing_channel );
1431+ testing_channel_drain_queued_tasks (& tester .testing_channel );
14131432
14141433 /* send response */
14151434 ASSERT_SUCCESS (s_send_response_str_ignore_errors (
@@ -1425,7 +1444,7 @@ static int s_test_close_from_callback(struct aws_allocator *allocator, enum requ
14251444 "0\r\n"
14261445 "\r\n" ));
14271446
1428- testing_channel_execute_queued_tasks (& tester .testing_channel );
1447+ testing_channel_drain_queued_tasks (& tester .testing_channel );
14291448
14301449 /* check that callbacks were invoked before close_at, but not after */
14311450 for (int i = 0 ; i < REQUEST_CALLBACK_COMPLETE ; ++ i ) {
0 commit comments