From 50d2e34e7148fef9e67428f8a533d37aab07bee9 Mon Sep 17 00:00:00 2001 From: Lizzy Fleckenstein Date: Sun, 12 Feb 2023 20:09:54 +0100 Subject: [PATCH] Fix reserialize exiting before finished --- tests/random.rs | 18 +++++++++--------- tests/reserialize/go.mod | 4 +++- tests/reserialize/main.go | 5 ++++- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/tests/random.rs b/tests/random.rs index d92ce79..e3b387a 100644 --- a/tests/random.rs +++ b/tests/random.rs @@ -29,9 +29,9 @@ where let input = T::generate_random_variant(&mut rng, i); - let mut writer = Vec::new(); + let mut input_payload = Vec::new(); input - .mt_serialize::(&mut writer) + .mt_serialize::(&mut input_payload) .map_err(|e| format!("serialize error: {e}\ninput: {input:?}"))?; let mut child = Command::new(&reserialize) @@ -42,13 +42,13 @@ where .spawn() .expect("failed to spawn reserialize"); - let mut stdin = child.stdin.take().expect("failed to open stdin"); - let payload = writer.clone(); + let mut stdin = child.stdin.take().unwrap(); + let stdin_payload = input_payload.clone(); std::thread::spawn(move || { - stdin.write_all(&payload).expect("failed to write to stdin"); + stdin.write_all(&stdin_payload).unwrap(); }); - let command_out = child.wait_with_output().expect("failed to read stdout"); + let command_out = child.wait_with_output().unwrap(); let stderr = String::from_utf8_lossy(&command_out.stderr); if command_out.status.success() { @@ -60,7 +60,7 @@ where return Err(format!( "reserialize returned failure\n\ input: {input:?}\n\ - input payload: {writer:?}\n\ + input payload: {input_payload:?}\n\ stderr: {stderr}" ) .into()); @@ -71,7 +71,7 @@ where format!( "deserialize error: {e}\n\ input: {input:?}\n\ - input payload: {writer:?}\n\ + input payload: {input_payload:?}\n\ output payload: {:?}\n\ stderr: {stderr}", reader.get_ref() @@ -83,7 +83,7 @@ where "output does not match input\n\ input: {input:?}\n\ output: {output:?}\n\ - input payload: {writer:?}\n\ + input payload: {input_payload:?}\n\ output payload: {:?}\n\ stderr: {stderr}", reader.get_ref(), diff --git a/tests/reserialize/go.mod b/tests/reserialize/go.mod index 34d806e..2c7628a 100644 --- a/tests/reserialize/go.mod +++ b/tests/reserialize/go.mod @@ -2,7 +2,9 @@ module github.com/minetest-rust/mt_net/tests/reserialize go 1.20 +replace github.com/dragonfireclient/mt => /home/fleckenstein/src/mt + require ( - github.com/dragonfireclient/mt v0.0.2-0.20230212182515-e1bfd543b068 // indirect + github.com/dragonfireclient/mt v0.0.2-0.20230212190852-7d9e314903cb // indirect github.com/klauspost/compress v1.15.15 // indirect ) diff --git a/tests/reserialize/main.go b/tests/reserialize/main.go index ef1b693..989b4c3 100644 --- a/tests/reserialize/main.go +++ b/tests/reserialize/main.go @@ -3,6 +3,7 @@ package main import ( "github.com/dragonfireclient/mt" "os" + "sync" ) func main() { @@ -14,5 +15,7 @@ func main() { os.Exit(1) } - mt.SerializePkt(*pkt, os.Stdout, toSrv) + var wg sync.WaitGroup + mt.SerializePkt(*pkt, os.Stdout, toSrv, &wg) + wg.Wait() } -- 2.44.0