]> git.lizzy.rs Git - mt_net.git/commitdiff
Fix reserialize exiting before finished
authorLizzy Fleckenstein <eliasfleckenstein@web.de>
Sun, 12 Feb 2023 19:09:54 +0000 (20:09 +0100)
committerLizzy Fleckenstein <eliasfleckenstein@web.de>
Sun, 12 Feb 2023 19:09:59 +0000 (20:09 +0100)
tests/random.rs
tests/reserialize/go.mod
tests/reserialize/main.go

index d92ce799407ac78270a3061cf54fd13db897b32e..e3b387ae44f8a5a6f4cc01b86705b69f9abf7d59 100644 (file)
@@ -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::<DefCfg>(&mut writer)
+                        .mt_serialize::<DefCfg>(&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(),
index 34d806efe786d90a746984f811106b2c670b69d8..2c7628ae7a0071864d349fa57101558a176ec843 100644 (file)
@@ -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
 )
index ef1b6939584657a610445f84780e67da345043fe..989b4c30c945058ae5fa51b86f40cd7ecb105e7f 100644 (file)
@@ -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()
 }