@@ -44,6 +44,7 @@ struct tester_options {
44
44
char * client_alpn_list ;
45
45
bool no_connection ; /* don't connect server to client */
46
46
bool pin_event_loop ;
47
+ bool use_tcp ; /* otherwise uses domain sockets */
47
48
};
48
49
49
50
/* Singleton used by tests in this file */
@@ -336,22 +337,23 @@ static int s_tester_init(struct tester *tester, const struct tester_options *opt
336
337
337
338
struct aws_socket_options socket_options = {
338
339
.type = AWS_SOCKET_STREAM ,
339
- .domain = AWS_SOCKET_LOCAL ,
340
+ .domain = options -> use_tcp ? AWS_SOCKET_IPV4 : AWS_SOCKET_LOCAL ,
340
341
.connect_timeout_ms =
341
342
(uint32_t )aws_timestamp_convert (TESTER_TIMEOUT_SEC , AWS_TIMESTAMP_SECS , AWS_TIMESTAMP_MILLIS , NULL ),
342
343
};
343
344
tester -> socket_options = socket_options ;
344
- /* Generate random address for endpoint */
345
- struct aws_uuid uuid ;
346
- ASSERT_SUCCESS (aws_uuid_init (& uuid ));
347
- char uuid_str [AWS_UUID_STR_LEN ];
348
- struct aws_byte_buf uuid_buf = aws_byte_buf_from_empty_array (uuid_str , sizeof (uuid_str ));
349
- ASSERT_SUCCESS (aws_uuid_to_str (& uuid , & uuid_buf ));
345
+
350
346
struct aws_socket_endpoint endpoint ;
351
347
AWS_ZERO_STRUCT (endpoint );
352
348
353
- snprintf (endpoint .address , sizeof (endpoint .address ), LOCAL_SOCK_TEST_FORMAT , uuid_str );
349
+ if (options -> use_tcp ) {
350
+ snprintf (endpoint .address , sizeof (endpoint .address ), "127.0.0.1" );
351
+ } else {
352
+ aws_socket_endpoint_init_local_address_for_test (& endpoint );
353
+ }
354
+
354
355
tester -> endpoint = endpoint ;
356
+
355
357
/* Create server (listening socket) */
356
358
struct aws_http_server_options server_options = AWS_HTTP_SERVER_OPTIONS_INIT ;
357
359
server_options .allocator = tester -> alloc ;
@@ -370,6 +372,14 @@ static int s_tester_init(struct tester *tester, const struct tester_options *opt
370
372
tester -> server = aws_http_server_new (& server_options );
371
373
ASSERT_NOT_NULL (tester -> server );
372
374
375
+ /*
376
+ * localhost server binds to any port, so let's get the final listener endpoint whether or not we're making
377
+ * connections to it.
378
+ */
379
+ if (options -> use_tcp ) {
380
+ tester -> endpoint = * aws_http_server_get_listener_endpoint (tester -> server );
381
+ }
382
+
373
383
/* If test doesn't need a connection, we're done setting up. */
374
384
if (options -> no_connection ) {
375
385
return AWS_OP_SUCCESS ;
@@ -448,6 +458,20 @@ static int s_test_server_new_destroy(struct aws_allocator *allocator, void *ctx)
448
458
}
449
459
AWS_TEST_CASE (server_new_destroy , s_test_server_new_destroy );
450
460
461
+ static int s_test_server_new_destroy_tcp (struct aws_allocator * allocator , void * ctx ) {
462
+ (void )ctx ;
463
+ struct tester_options options = {.alloc = allocator , .no_connection = true, .use_tcp = true};
464
+ struct tester tester ;
465
+ ASSERT_SUCCESS (s_tester_init (& tester , & options ));
466
+
467
+ const struct aws_socket_endpoint * listener_endpoint = aws_http_server_get_listener_endpoint (tester .server );
468
+ ASSERT_TRUE (listener_endpoint -> port > 0 );
469
+
470
+ ASSERT_SUCCESS (s_tester_clean_up (& tester ));
471
+ return AWS_OP_SUCCESS ;
472
+ }
473
+ AWS_TEST_CASE (server_new_destroy_tcp , s_test_server_new_destroy_tcp );
474
+
451
475
void release_all_client_connections (struct tester * tester ) {
452
476
for (int i = 0 ; i < tester -> client_connection_num ; i ++ ) {
453
477
aws_http_connection_release (tester -> client_connections [i ]);
0 commit comments