Skip to content

Commit 65a40ec

Browse files
committed
test(jetsocat): stabilize jmux proxy hello world test
Make the async JMUX write test wait for listeners explicitly, use the tokio command variant, close the read server stdin, and disable proxy auto-detection for the final client invocation. This removes a local Windows-only source of flakiness while keeping the test behavior the same.
1 parent 78335e0 commit 65a40ec

1 file changed

Lines changed: 25 additions & 19 deletions

File tree

testsuite/tests/cli/jetsocat.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::io::Read;
21
use std::sync::Arc;
32
use std::time::Duration;
43

@@ -216,77 +215,84 @@ fn jmux_proxy_read_hello_world() {
216215
client_output.success().stdout("hello world\n");
217216
}
218217

219-
#[test]
220-
fn jmux_proxy_write_hello_world() {
218+
#[tokio::test]
219+
async fn jmux_proxy_write_hello_world() {
220+
use tokio::io::AsyncReadExt as _;
221+
221222
// Find 3 available ports at once to avoid conflicts.
222223
let ports = find_unused_ports(3);
223224
let read_server_port = ports[0];
224225
let jmux_server_port = ports[1];
225226
let proxy_listen_port = ports[2];
226227

227228
// Start read server first.
228-
let mut read_server = jetsocat_cmd()
229+
let mut read_server = jetsocat_tokio_cmd()
229230
.env(
230231
"JETSOCAT_ARGS",
231232
format!("forward tcp-listen://127.0.0.1:{read_server_port} stdio --no-proxy"),
232233
)
234+
.stdin(std::process::Stdio::null())
233235
.stdout(std::process::Stdio::piped())
236+
.kill_on_drop(true)
234237
.spawn()
235238
.expect("failed to start read server");
236239

237-
// Give the read server time to start.
238-
std::thread::sleep(LISTENER_WAIT_DURATION);
240+
wait_for_port_bound(read_server_port).await.expect("read server ready");
239241

240242
// Start JMUX server that will accept JMUX connections.
241-
let mut jmux_server = jetsocat_cmd()
243+
let mut jmux_server = jetsocat_tokio_cmd()
242244
.env(
243245
"JETSOCAT_ARGS",
244246
format!("jmux-proxy tcp-listen://127.0.0.1:{jmux_server_port} --allow-all --no-proxy"),
245247
)
248+
.kill_on_drop(true)
246249
.spawn()
247250
.expect("failed to start JMUX server");
248251

249-
// Give the JMUX server time to start.
250-
std::thread::sleep(LISTENER_WAIT_DURATION);
252+
wait_for_port_bound(jmux_server_port).await.expect("JMUX server ready");
251253

252254
// Start JMUX client proxy that connects to the JMUX server and provides a local TCP listener.
253-
let mut jmux_client = jetsocat_cmd()
255+
let mut jmux_client = jetsocat_tokio_cmd()
254256
.env(
255257
"JETSOCAT_ARGS",
256258
format!(
257259
"jmux-proxy tcp://127.0.0.1:{jmux_server_port} tcp-listen://127.0.0.1:{proxy_listen_port}/127.0.0.1:{read_server_port} --no-proxy",
258260
),
259261
)
262+
.kill_on_drop(true)
260263
.spawn()
261264
.expect("failed to start JMUX client");
262265

263-
// Give the JMUX client time to establish connection and set up listener.
264-
std::thread::sleep(LISTENER_WAIT_DURATION);
266+
wait_for_port_bound(proxy_listen_port)
267+
.await
268+
.expect("JMUX client proxy ready");
265269

266270
// Connect to the JMUX client's local listener.
267271
jetsocat_assert_cmd()
268272
.env(
269273
"JETSOCAT_ARGS",
270-
format!("forward tcp://127.0.0.1:{proxy_listen_port} 'cmd://echo hello world'"),
274+
format!("forward tcp://127.0.0.1:{proxy_listen_port} 'cmd://echo hello world' --no-proxy"),
271275
)
272276
.timeout(COMMAND_TIMEOUT)
273277
.assert()
274278
.success();
275279

276280
// Kill all processes.
277-
let _ = jmux_client.kill();
278-
let _ = jmux_server.kill();
279-
let _ = read_server.kill();
280-
let _ = jmux_client.wait();
281-
let _ = jmux_server.wait();
282-
let _ = read_server.wait();
281+
let _ = jmux_client.start_kill();
282+
let _ = jmux_server.start_kill();
283+
let _ = read_server.start_kill();
284+
let _ = jmux_client.wait().await;
285+
let _ = jmux_server.wait().await;
286+
let _ = read_server.wait().await;
283287

284288
// Check that the read server received the payload.
285289
let mut read_server_stdout = String::new();
286290
read_server
287291
.stdout
292+
.take()
288293
.unwrap()
289294
.read_to_string(&mut read_server_stdout)
295+
.await
290296
.unwrap();
291297
assert_eq!(read_server_stdout.trim(), "hello world");
292298
}

0 commit comments

Comments
 (0)