|
19 | 19 | // ------- |
20 | 20 | use std::{ |
21 | 21 | path::{MAIN_SEPARATOR_STR, PathBuf}, |
22 | | - thread::{self, sleep}, |
| 22 | + thread::sleep, |
23 | 23 | time::Duration, |
24 | 24 | }; |
25 | 25 |
|
@@ -133,24 +133,24 @@ fn test_path_to_url() { |
133 | 133 | fn test_other_path() { |
134 | 134 | let (temp_dir, test_dir) = prep_test_dir!(); |
135 | 135 |
|
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. |
148 | 146 | get_server() |
149 | 147 | .args(["--port", "8083", "stop"]) |
150 | 148 | .current_dir(&test_dir) |
151 | 149 | .assert() |
152 | 150 | .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)); |
154 | 154 |
|
155 | 155 | // Report any errors produced when removing the temporary directory. |
156 | 156 | temp_dir.close().unwrap(); |
|
0 commit comments