diff --git a/src/runtime2/tests/internet.rs b/src/runtime2/tests/internet.rs index 4859ca49ef963f54db2e9dbf0140f0707c4fe145..6cb03b954005b551198ecc3add8df9f94a6e9786 100644 --- a/src/runtime2/tests/internet.rs +++ b/src/runtime2/tests/internet.rs @@ -79,10 +79,10 @@ fn test_tcp_listener_and_client() { import std.internet::*; func listen_port() -> u16 { - return 2393; + return 2392; } - comp server(u32 num_connections) { + comp server(u32 num_connections, in<()> shutdown) { // Start tcp listener channel listen_cmd_tx -> listen_cmd_rx; channel listen_conn_tx -> listen_conn_rx; @@ -113,6 +113,8 @@ fn test_tcp_listener_and_client() { // Shut down the listener print(\"server: shutting down listener\"); + sync auto v = get(shutdown); + sync put(listen_cmd_tx, ListenerCmd::Shutdown); } // Waits for a single TCP byte (to simplify potentially having to @@ -137,7 +139,7 @@ fn test_tcp_listener_and_client() { sync put(conn.tx, ClientCmd::Shutdown); } - comp echo_requester(u8 byte_to_send) { + comp echo_requester(u8 byte_to_send, out<()> done) { channel cmd_tx -> cmd_rx; channel data_tx -> data_rx; new tcp_client({127, 0, 0, 1}, listen_port(), cmd_rx, data_tx); @@ -163,16 +165,32 @@ fn test_tcp_listener_and_client() { // Shut down the TCP connection print(\"requester: shutting down TCP component\"); sync put(cmd_tx, ClientCmd::Shutdown); + sync put(done, ()); } comp constructor() { auto num_connections = 1; - new server(num_connections); + channel shutdown_listener_tx -> shutdown_listener_rx; + new server(num_connections, shutdown_listener_rx); auto connection_index = 0; + auto all_done = {}; while (connection_index < num_connections) { - new echo_requester(cast(connection_index)); + channel done_tx -> done_rx; + new echo_requester(cast(connection_index), done_tx); + connection_index += 1; + all_done @= {done_rx}; } + + auto counter = 0; + while (counter < length(all_done)) { + print(\"constructor: waiting for requester to exit\"); + sync auto v = get(all_done[counter]); + counter += 1; + } + + print(\"constructor: instructing listener to exit\"); + sync put(shutdown_listener_tx, ()); } ", "constructor", no_args()); } \ No newline at end of file