Skip to content

Commit dea0b98

Browse files
committed
Fix the tcp_echo_server test to avoid hangs.
Shut down the writing end of the socket after writing, to allow the server to end the stream, allowing a `read_to_end` on the reading end to reach the end of the stream.
1 parent 7205737 commit dea0b98

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

test-programs/artifacts/tests/tcp_echo_server.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn run_in_wasmtime(wasm: &[u8], stdout: Option<MemoryOutputPipe>) -> Result<()>
7777
#[test_log::test]
7878
fn tcp_echo_server() -> Result<()> {
7979
use std::io::{Read, Write};
80-
use std::net::TcpStream;
80+
use std::net::{Shutdown, TcpStream};
8181
use std::thread::sleep;
8282
use std::time::Duration;
8383

@@ -106,6 +106,8 @@ fn tcp_echo_server() -> Result<()> {
106106
tcpstream.write_all(MESSAGE).context("write to socket")?;
107107
println!("wrote to echo server");
108108

109+
tcpstream.shutdown(Shutdown::Write)?;
110+
109111
let mut readback = Vec::new();
110112
tcpstream
111113
.read_to_end(&mut readback)

0 commit comments

Comments
 (0)