On Wed, Jul 19, 2023 at 09:09:51AM +0000, Tage Johansson wrote: > A couple of integration tests are added in rust/tests. They are mostly > ported from the OCaml tests. > --- > rust/tests/test_210_opt_abort.rs | 39 +++++ > rust/tests/test_220_opt_list.rs | 85 +++++++++++
I noticed something today while working on issues with nbd_opt_abort vs. nbd_shutdown: > diff --git a/rust/tests/test_220_opt_list.rs b/rust/tests/test_220_opt_list.rs > new file mode 100644 > index 0000000..5abec5f > --- /dev/null > +++ b/rust/tests/test_220_opt_list.rs > @@ -0,0 +1,85 @@ > + > +impl ConnTester { > + fn new() -> Self { > + let srcdir = env::var("srcdir").unwrap(); > + let srcdir = Path::new(&srcdir); > + let script_path = srcdir.join("../tests/opt-list.sh"); > + let script_path = > + CString::new(script_path.into_os_string().into_vec()).unwrap(); > + Self { script_path } > + } > + > + fn connect( This function is modeled after the 'let conn' function in test_220_opt_list.ml; however,... > + &self, > + mode: u8, > + expected_exports: &[&CStr], > + ) -> libnbd::Result<()> { > + let nbd = libnbd::Handle::new().unwrap(); > + nbd.set_opt_mode(true).unwrap(); > + nbd.connect_command(&[ > + c_str!("nbdkit"), > + c_str!("-s"), > + c_str!("--exit-with-parent"), > + c_str!("-v"), > + c_str!("sh"), > + &self.script_path, > + &CString::new(format!("mode={mode}")).unwrap(), > + ]) > + .unwrap(); > + > + // Collect all exports in this list. > + let exports = Arc::new(Mutex::new(Vec::new())); > + let exports_clone = exports.clone(); > + let count = nbd.opt_list(move |name, _| { > + exports_clone.lock().unwrap().push(name.to_owned()); > + 0 > + })?; > + let exports = > Arc::into_inner(exports).unwrap().into_inner().unwrap(); > + assert_eq!(exports.len(), count as usize); > + assert_eq!(exports.len(), expected_exports.len()); > + for (export, &expected) in exports.iter().zip(expected_exports) { > + assert_eq!(export.as_c_str(), expected); > + } > + Ok(()) ...the OCaml version calls 'NBD.opt_abort nbd' after verifying that exports match the expected list, while the Rust code does not. You can see the same thing in the Python tests (calling opt_abort before closing the handle). This means that for the Rust tests, the server is more likely to issue an error message about the client abruptly disconnecting, which doesn't really affect the test passing or failing, but adds spurious noise to the log files if we are ever trying to decipher whether two language bindings are doing the same thing. Also affected: 240, 245, and their async counterpart tests. -- Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org _______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://listman.redhat.com/mailman/listinfo/libguestfs