Skip to content

Commit b9bd125

Browse files
committed
Fix: improve process control to work around test failures.
1 parent edc4e8d commit b9bd125

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

server/src/webserver/tests.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// -------
2020
use std::{
2121
path::{MAIN_SEPARATOR_STR, PathBuf},
22-
thread::{self, sleep},
22+
thread::sleep,
2323
time::Duration,
2424
};
2525

@@ -133,24 +133,24 @@ fn test_path_to_url() {
133133
fn test_other_path() {
134134
let (temp_dir, test_dir) = prep_test_dir!();
135135

136-
// Start the server.
137-
let test_dir1 = test_dir.clone();
138-
let handle = thread::spawn(move || {
139-
get_server()
140-
.args(["--port", "8083", "start"])
141-
.current_dir(&test_dir1)
142-
.assert()
143-
.success();
144-
});
145-
// The server waits for up to 3 seconds for a ping to work. Add some extra
146-
// time for starting the process.
147-
sleep(Duration::from_millis(6000));
136+
// Start the server. Calling `output()` causes the program to hang; call
137+
// `status()` instead. Since the `assert_cmd` crates doesn't offer this,
138+
// use the std lib instead.
139+
std::process::Command::new(get_server().get_program())
140+
.args(["--port", "8083", "start"])
141+
.current_dir(&test_dir)
142+
.status()
143+
.expect("failed to start server");
144+
145+
// Stop it.
148146
get_server()
149147
.args(["--port", "8083", "stop"])
150148
.current_dir(&test_dir)
151149
.assert()
152150
.success();
153-
handle.join().unwrap();
151+
152+
// Wait for the server to exit, since it locks the temp_dir.
153+
sleep(Duration::from_millis(3000));
154154

155155
// Report any errors produced when removing the temporary directory.
156156
temp_dir.close().unwrap();

0 commit comments

Comments
 (0)