Shutdown mesh in tests
This change properly shuts down mesh instances in tests.  This will
resulting in the cleanup of a number of threads.
@@ -400,13 +400,16 @@ mod tests {
let handle = thread::spawn(move || {
let client = assert_ok(transport.connect(&endpoint));
- let mesh = Mesh::new(1, 1);
+ let mut mesh = Mesh::new(1, 1);
assert_ok(mesh.add(client, "client".to_string()));
assert_ok(mesh.send(Envelope::new("client".to_string(), b"hello".to_vec())));
+
+ mesh.signal_shutdown();
+ mesh.wait_for_shutdown().unwrap();
});
- let mesh = Mesh::new(1, 1);
+ let mut mesh = Mesh::new(1, 1);
let server = assert_ok(listener.accept());
assert_ok(mesh.add(server, "server".to_string()));
@@ -416,6 +419,9 @@ mod tests {
assert_eq!("server", envelope.id());
handle.join().unwrap();
+
+ mesh.signal_shutdown();
+ mesh.wait_for_shutdown().unwrap();
}
// Test that connections can be added and removed from a Mesh
@@ -423,7 +429,7 @@ mod tests {
let mut listener = assert_ok(transport.listen(bind));
let endpoint = listener.endpoint();
- let mesh = Mesh::new(0, 0);
+ let mut mesh = Mesh::new(0, 0);
let mut ids = Vec::new();
@@ -455,6 +461,9 @@ mod tests {
for id in &ids {
assert_ok(mesh.remove(id));
}
+
+ mesh.signal_shutdown();
+ mesh.wait_for_shutdown().unwrap();
}
// Test that many connections can be added to a Mesh and sent and received from
@@ -464,7 +473,7 @@ mod tests {
let mut listener = assert_ok(transport.listen(bind));
let endpoint = listener.endpoint();
- let mesh = Mesh::new(CONNECTIONS, CONNECTIONS);
+ let mut mesh = Mesh::new(CONNECTIONS, CONNECTIONS);
let (client_ready_tx, client_ready_rx) = channel();
let (server_ready_tx, server_ready_rx) = channel();
@@ -519,6 +528,9 @@ mod tests {
}
handle.join().unwrap();
+
+ mesh.signal_shutdown();
+ mesh.wait_for_shutdown().unwrap();
}
#[test]
