@@ -44,6 +44,7 @@ struct tester_options {
4444 char * client_alpn_list ;
4545 bool no_connection ; /* don't connect server to client */
4646 bool pin_event_loop ;
47+ bool use_tcp ; /* otherwise uses domain sockets */
4748};
4849
4950/* Singleton used by tests in this file */
@@ -336,22 +337,23 @@ static int s_tester_init(struct tester *tester, const struct tester_options *opt
336337
337338 struct aws_socket_options socket_options = {
338339 .type = AWS_SOCKET_STREAM ,
339- .domain = AWS_SOCKET_LOCAL ,
340+ .domain = options -> use_tcp ? AWS_SOCKET_IPV4 : AWS_SOCKET_LOCAL ,
340341 .connect_timeout_ms =
341342 (uint32_t )aws_timestamp_convert (TESTER_TIMEOUT_SEC , AWS_TIMESTAMP_SECS , AWS_TIMESTAMP_MILLIS , NULL ),
342343 };
343344 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+
350346 struct aws_socket_endpoint endpoint ;
351347 AWS_ZERO_STRUCT (endpoint );
352348
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+
354355 tester -> endpoint = endpoint ;
356+
355357 /* Create server (listening socket) */
356358 struct aws_http_server_options server_options = AWS_HTTP_SERVER_OPTIONS_INIT ;
357359 server_options .allocator = tester -> alloc ;
@@ -370,6 +372,14 @@ static int s_tester_init(struct tester *tester, const struct tester_options *opt
370372 tester -> server = aws_http_server_new (& server_options );
371373 ASSERT_NOT_NULL (tester -> server );
372374
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+
373383 /* If test doesn't need a connection, we're done setting up. */
374384 if (options -> no_connection ) {
375385 return AWS_OP_SUCCESS ;
@@ -448,6 +458,20 @@ static int s_test_server_new_destroy(struct aws_allocator *allocator, void *ctx)
448458}
449459AWS_TEST_CASE (server_new_destroy , s_test_server_new_destroy );
450460
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+
451475void release_all_client_connections (struct tester * tester ) {
452476 for (int i = 0 ; i < tester -> client_connection_num ; i ++ ) {
453477 aws_http_connection_release (tester -> client_connections [i ]);
0 commit comments