Skip to content

Commit f699ca9

Browse files
Erik Schillingstefano-garzarella
authored andcommitted
vhost-user-backend: simplify tests
Scoping the threads allows us to just borrow the values from the thread and removes the need for the clones with the slightly awkward names. Also, we no longer need to remember to join threads (happens automatically upon end of scope). No functional changes intended. Signed-off-by: Erik Schilling <[email protected]>
1 parent f50b135 commit f699ca9

File tree

1 file changed

+32
-33
lines changed
  • crates/vhost-user-backend/src

1 file changed

+32
-33
lines changed

crates/vhost-user-backend/src/lib.rs

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -213,23 +213,22 @@ mod tests {
213213
let tmpdir = tempfile::tempdir().unwrap();
214214
let path = tmpdir.path().join("socket");
215215

216-
let barrier2 = barrier.clone();
217-
let path1 = path.clone();
218-
let thread = thread::spawn(move || {
219-
barrier2.wait();
220-
let socket = UnixStream::connect(&path1).unwrap();
221-
barrier2.wait();
222-
drop(socket)
216+
thread::scope(|s| {
217+
s.spawn(|| {
218+
barrier.wait();
219+
let socket = UnixStream::connect(&path).unwrap();
220+
barrier.wait();
221+
drop(socket)
222+
});
223+
224+
let listener = Listener::new(&path, false).unwrap();
225+
barrier.wait();
226+
daemon.start(listener).unwrap();
227+
barrier.wait();
228+
// Above process generates a `HandleRequest(PartialMessage)` error.
229+
daemon.wait().unwrap_err();
230+
daemon.wait().unwrap();
223231
});
224-
225-
let listener = Listener::new(&path, false).unwrap();
226-
barrier.wait();
227-
daemon.start(listener).unwrap();
228-
barrier.wait();
229-
// Above process generates a `HandleRequest(PartialMessage)` error.
230-
daemon.wait().unwrap_err();
231-
daemon.wait().unwrap();
232-
thread.join().unwrap();
233232
}
234233

235234
#[test]
@@ -247,24 +246,24 @@ mod tests {
247246
let tmpdir = tempfile::tempdir().unwrap();
248247
let path = tmpdir.path().join("socket");
249248

250-
let barrier2 = barrier.clone();
251-
let path1 = path.clone();
252-
let thread = thread::spawn(move || {
253-
let listener = UnixListener::bind(&path1).unwrap();
254-
barrier2.wait();
255-
let (stream, _) = listener.accept().unwrap();
256-
barrier2.wait();
257-
drop(stream)
249+
thread::scope(|s| {
250+
s.spawn(|| {
251+
let listener = UnixListener::bind(&path).unwrap();
252+
barrier.wait();
253+
let (stream, _) = listener.accept().unwrap();
254+
barrier.wait();
255+
drop(stream)
256+
});
257+
258+
barrier.wait();
259+
daemon
260+
.start_client(path.as_path().to_str().unwrap())
261+
.unwrap();
262+
barrier.wait();
263+
// Above process generates a `HandleRequest(PartialMessage)` error.
264+
daemon.wait().unwrap_err();
265+
daemon.wait().unwrap();
258266
});
259267

260-
barrier.wait();
261-
daemon
262-
.start_client(path.as_path().to_str().unwrap())
263-
.unwrap();
264-
barrier.wait();
265-
// Above process generates a `HandleRequest(PartialMessage)` error.
266-
daemon.wait().unwrap_err();
267-
daemon.wait().unwrap();
268-
thread.join().unwrap();
269268
}
270269
}

0 commit comments

Comments
 (0)