@@ -80,6 +80,8 @@ static int s_tester_init(struct tester *tester, struct aws_allocator *alloc) {
80
80
81
81
aws_channel_acquire_hold (tester -> testing_channel .channel );
82
82
83
+ testing_channel_drain_queued_tasks (& tester -> testing_channel );
84
+
83
85
return AWS_OP_SUCCESS ;
84
86
}
85
87
@@ -150,7 +152,7 @@ H1_CLIENT_TEST_CASE(h1_client_request_send_1liner) {
150
152
struct aws_http_stream * stream = aws_http_stream_new_client_request (& opt );
151
153
ASSERT_NOT_NULL (stream );
152
154
153
- testing_channel_execute_queued_tasks (& tester .testing_channel );
155
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
154
156
155
157
/* check result */
156
158
const char * expected = "GET / HTTP/1.1\r\n"
@@ -190,7 +192,7 @@ H1_CLIENT_TEST_CASE(h1_client_request_send_headers) {
190
192
struct aws_http_stream * stream = aws_http_stream_new_client_request (& opt );
191
193
ASSERT_NOT_NULL (stream );
192
194
193
- testing_channel_execute_queued_tasks (& tester .testing_channel );
195
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
194
196
195
197
/* check result */
196
198
const char * expected = "GET / HTTP/1.1\r\n"
@@ -255,7 +257,7 @@ H1_CLIENT_TEST_CASE(h1_client_request_send_body) {
255
257
struct aws_http_stream * stream = aws_http_stream_new_client_request (& opt );
256
258
ASSERT_NOT_NULL (stream );
257
259
258
- testing_channel_execute_queued_tasks (& tester .testing_channel );
260
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
259
261
260
262
/* check result */
261
263
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
290
292
while (remaining > 0 ) {
291
293
/* Tick event loop if there are no messages already */
292
294
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 );
294
296
}
295
297
296
298
/* 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
317
319
}
318
320
319
321
/* 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 );
321
323
ASSERT_TRUE (aws_linked_list_empty (msgs ));
322
324
323
325
* out_num_messages = num_messages ;
@@ -470,7 +472,7 @@ H1_CLIENT_TEST_CASE(h1_client_request_send_multiple_in_1_io_message) {
470
472
ASSERT_NOT_NULL (streams [i ]);
471
473
}
472
474
473
- testing_channel_execute_queued_tasks (& tester .testing_channel );
475
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
474
476
475
477
/* check result */
476
478
const char * expected = "GET / HTTP/1.1\r\n"
@@ -676,11 +678,13 @@ H1_CLIENT_TEST_CASE(h1_client_response_get_1liner) {
676
678
struct response_tester response ;
677
679
ASSERT_SUCCESS (s_response_tester_init (& response , allocator , & opt ));
678
680
679
- testing_channel_execute_queued_tasks (& tester .testing_channel );
681
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
680
682
681
683
/* send response */
682
684
ASSERT_SUCCESS (s_send_response_str (& tester , "HTTP/1.1 204 No Content\r\n\r\n" ));
683
685
686
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
687
+
684
688
/* check result */
685
689
ASSERT_TRUE (response .on_complete_cb_count == 1 );
686
690
ASSERT_TRUE (response .on_complete_error_code == AWS_ERROR_SUCCESS );
@@ -719,7 +723,7 @@ H1_CLIENT_TEST_CASE(h1_client_response_get_headers) {
719
723
struct response_tester response ;
720
724
ASSERT_SUCCESS (s_response_tester_init (& response , allocator , & opt ));
721
725
722
- testing_channel_execute_queued_tasks (& tester .testing_channel );
726
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
723
727
724
728
/* send response */
725
729
ASSERT_SUCCESS (s_send_response_str (
@@ -729,6 +733,8 @@ H1_CLIENT_TEST_CASE(h1_client_response_get_headers) {
729
733
"Location: /index.html\r\n"
730
734
"\r\n" ));
731
735
736
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
737
+
732
738
/* check result */
733
739
ASSERT_TRUE (response .on_complete_cb_count == 1 );
734
740
ASSERT_TRUE (response .on_complete_error_code == AWS_ERROR_SUCCESS );
@@ -759,7 +765,7 @@ H1_CLIENT_TEST_CASE(h1_client_response_get_body) {
759
765
struct response_tester response ;
760
766
ASSERT_SUCCESS (s_response_tester_init (& response , allocator , & opt ));
761
767
762
- testing_channel_execute_queued_tasks (& tester .testing_channel );
768
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
763
769
764
770
/* send response */
765
771
ASSERT_SUCCESS (s_send_response_str (
@@ -769,6 +775,8 @@ H1_CLIENT_TEST_CASE(h1_client_response_get_body) {
769
775
"\r\n"
770
776
"Call Momo" ));
771
777
778
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
779
+
772
780
/* check result */
773
781
ASSERT_TRUE (response .on_complete_cb_count == 1 );
774
782
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) {
799
807
struct response_tester response ;
800
808
ASSERT_SUCCESS (s_response_tester_init (& response , allocator , & opt ));
801
809
802
- testing_channel_execute_queued_tasks (& tester .testing_channel );
810
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
803
811
804
812
/* send response with each byte in its own aws_io_message */
805
813
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) {
811
819
s_send_response (& tester , aws_byte_cursor_from_array (response_str + i , 1 ));
812
820
}
813
821
822
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
823
+
814
824
/* check result */
815
825
ASSERT_TRUE (response .on_complete_cb_count == 1 );
816
826
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) {
841
851
struct response_tester responses [3 ];
842
852
for (size_t i = 0 ; i < AWS_ARRAY_SIZE (responses ); ++ i ) {
843
853
ASSERT_SUCCESS (s_response_tester_init (& responses [i ], allocator , & opt ));
844
-
845
- testing_channel_execute_queued_tasks (& tester .testing_channel );
846
854
}
855
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
847
856
848
857
/* send all responses in a single aws_io_message */
849
858
ASSERT_SUCCESS (s_send_response_str (
@@ -852,6 +861,8 @@ H1_CLIENT_TEST_CASE(h1_client_response_get_multiple_from_1_io_message) {
852
861
"HTTP/1.1 204 No Content\r\n\r\n"
853
862
"HTTP/1.1 204 No Content\r\n\r\n" ));
854
863
864
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
865
+
855
866
/* check results */
856
867
for (size_t i = 0 ; i < AWS_ARRAY_SIZE (responses ); ++ i ) {
857
868
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) {
882
893
struct response_tester response ;
883
894
ASSERT_SUCCESS (s_response_tester_init (& response , allocator , & opt ));
884
895
885
- testing_channel_execute_queued_tasks (& tester .testing_channel );
896
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
886
897
887
898
/* send response */
888
899
ASSERT_SUCCESS (s_send_response_str_ignore_errors (& tester , "Mmmm garbage data\r\n\r\n" ));
889
900
890
- testing_channel_execute_queued_tasks (& tester .testing_channel );
901
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
891
902
892
903
/* check result */
893
904
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)
914
925
915
926
struct response_tester response ;
916
927
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 );
918
929
919
930
/* send 2 responses in a single aws_io_message. */
920
931
ASSERT_SUCCESS (s_send_response_ex (
@@ -923,6 +934,8 @@ H1_CLIENT_TEST_CASE(h1_client_response_with_too_much_data_shuts_down_connection)
923
934
"HTTP/1.1 204 No Content\r\n\r\n" ),
924
935
true /* ignore send errors */ ));
925
936
937
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
938
+
926
939
/* 1st response should have come across successfully */
927
940
ASSERT_TRUE (response .on_complete_cb_count == 1 );
928
941
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)
933
946
ASSERT_SUCCESS (s_response_tester_clean_up (& response ));
934
947
935
948
/* 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 );
937
950
ASSERT_TRUE (tester .is_shut_down );
938
951
ASSERT_TRUE (tester .shutdown_error_code != AWS_ERROR_SUCCESS );
939
952
@@ -1009,14 +1022,17 @@ H1_CLIENT_TEST_CASE(h1_client_response_arrives_before_request_done_sending_is_ok
1009
1022
ASSERT_SUCCESS (s_response_tester_init_ex (& response , allocator , & opt , & body_sender ));
1010
1023
1011
1024
/* send head of request */
1012
- testing_channel_execute_queued_tasks (& tester .testing_channel );
1025
+ testing_channel_run_currently_queued_tasks (& tester .testing_channel );
1013
1026
1014
1027
/* send response */
1015
1028
ASSERT_SUCCESS (s_send_response_str (& tester , "HTTP/1.1 200 OK\r\n\r\n" ));
1016
1029
1017
1030
/* tick loop until body finishes sending.*/
1018
1031
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 );
1020
1036
}
1021
1037
1022
1038
/* check result */
@@ -1046,7 +1062,7 @@ H1_CLIENT_TEST_CASE(h1_client_response_without_request_shuts_down_connection) {
1046
1062
ASSERT_SUCCESS (s_tester_init (& tester , allocator ));
1047
1063
1048
1064
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 );
1050
1066
1051
1067
ASSERT_TRUE (tester .is_shut_down );
1052
1068
ASSERT_TRUE (tester .shutdown_error_code != AWS_ERROR_SUCCESS );
@@ -1071,7 +1087,7 @@ H1_CLIENT_TEST_CASE(h1_client_window_reopens_by_default) {
1071
1087
struct response_tester response ;
1072
1088
ASSERT_SUCCESS (s_response_tester_init (& response , allocator , & opt ));
1073
1089
1074
- testing_channel_execute_queued_tasks (& tester .testing_channel );
1090
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
1075
1091
1076
1092
/* send response */
1077
1093
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) {
1080
1096
"Call Momo" ;
1081
1097
ASSERT_SUCCESS (s_send_response_str (& tester , response_str ));
1082
1098
1099
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
1100
+
1083
1101
/* check result */
1084
1102
size_t window_update = testing_channel_last_window_update (& tester .testing_channel );
1085
1103
ASSERT_TRUE (window_update == strlen (response_str ));
@@ -1106,7 +1124,7 @@ H1_CLIENT_TEST_CASE(h1_client_window_shrinks_if_user_says_so) {
1106
1124
ASSERT_SUCCESS (s_response_tester_init (& response , allocator , & opt ));
1107
1125
response .stop_auto_window_update = true;
1108
1126
1109
- testing_channel_execute_queued_tasks (& tester .testing_channel );
1127
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
1110
1128
1111
1129
/* send response */
1112
1130
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) {
1115
1133
"Call Momo" ;
1116
1134
ASSERT_SUCCESS (s_send_response_str (& tester , response_str ));
1117
1135
1136
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
1137
+
1118
1138
/* check result */
1119
1139
size_t window_update = testing_channel_last_window_update (& tester .testing_channel );
1120
1140
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) {
1141
1161
ASSERT_SUCCESS (s_response_tester_init (& response , allocator , & opt ));
1142
1162
response .stop_auto_window_update = true;
1143
1163
1144
- testing_channel_execute_queued_tasks (& tester .testing_channel );
1164
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
1145
1165
1146
1166
/* send response */
1147
1167
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) {
1151
1171
ASSERT_SUCCESS (s_send_response_str (& tester , response_str ));
1152
1172
1153
1173
/* 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 );
1155
1175
1156
1176
/* check result */
1157
1177
if (!on_thread ) {
@@ -1162,9 +1182,9 @@ static int s_window_update(struct aws_allocator *allocator, bool on_thread) {
1162
1182
1163
1183
if (!on_thread ) {
1164
1184
testing_channel_set_is_on_users_thread (& tester .testing_channel , true);
1165
- testing_channel_execute_queued_tasks (& tester .testing_channel );
1166
1185
}
1167
- testing_channel_execute_queued_tasks (& tester .testing_channel );
1186
+
1187
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
1168
1188
1169
1189
size_t window_update = testing_channel_last_window_update (& tester .testing_channel );
1170
1190
ASSERT_INT_EQUALS (9 , window_update );
@@ -1208,11 +1228,11 @@ H1_CLIENT_TEST_CASE(h1_client_request_cancelled_by_channel_shutdown) {
1208
1228
struct aws_http_stream * stream = aws_http_stream_new_client_request (& opt );
1209
1229
ASSERT_NOT_NULL (stream );
1210
1230
1211
- testing_channel_execute_queued_tasks (& tester .testing_channel );
1231
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
1212
1232
1213
1233
/* shutdown channel before request completes */
1214
1234
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 );
1216
1236
1217
1237
/* even though the channel shut down with error_code 0,
1218
1238
* 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) {
1247
1267
}
1248
1268
1249
1269
/* 2 streams are now in-progress */
1250
- testing_channel_execute_queued_tasks (& tester .testing_channel );
1270
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
1251
1271
1252
1272
/* Make 1 more stream that's still locked away in the pending queue */
1253
1273
opt .user_data = & completion_error_codes [2 ];
@@ -1256,7 +1276,7 @@ H1_CLIENT_TEST_CASE(h1_client_multiple_requests_cancelled_by_channel_shutdown) {
1256
1276
1257
1277
/* shutdown channel */
1258
1278
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 );
1260
1280
1261
1281
/* check results */
1262
1282
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
1379
1399
static int s_test_close_from_callback (struct aws_allocator * allocator , enum request_callback close_at ) {
1380
1400
struct tester tester ;
1381
1401
ASSERT_SUCCESS (s_tester_init (& tester , allocator ));
1382
- testing_channel_execute_queued_tasks (& tester .testing_channel );
1383
1402
1384
1403
struct close_from_callback_tester close_tester = {
1385
1404
.close_at = close_at ,
@@ -1409,7 +1428,7 @@ static int s_test_close_from_callback(struct aws_allocator *allocator, enum requ
1409
1428
struct aws_http_stream * stream = aws_http_stream_new_client_request (& opt );
1410
1429
ASSERT_NOT_NULL (stream );
1411
1430
1412
- testing_channel_execute_queued_tasks (& tester .testing_channel );
1431
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
1413
1432
1414
1433
/* send response */
1415
1434
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
1425
1444
"0\r\n"
1426
1445
"\r\n" ));
1427
1446
1428
- testing_channel_execute_queued_tasks (& tester .testing_channel );
1447
+ testing_channel_drain_queued_tasks (& tester .testing_channel );
1429
1448
1430
1449
/* check that callbacks were invoked before close_at, but not after */
1431
1450
for (int i = 0 ; i < REQUEST_CALLBACK_COMPLETE ; ++ i ) {
0 commit comments