Skip to content

Commit af448e8

Browse files
committed
Revert "tests: share http server between tests (denoland#3336)"
This reverts commit dbf861f.
1 parent 9ffebd6 commit af448e8

File tree

2 files changed

+47
-44
lines changed

2 files changed

+47
-44
lines changed

cli/test_util.rs

Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ use std::path::PathBuf;
88
use std::process::Child;
99
use std::process::Command;
1010
use std::process::Stdio;
11-
use std::sync::atomic::AtomicUsize;
12-
use std::sync::atomic::Ordering;
1311
use std::sync::Mutex;
12+
use std::sync::MutexGuard;
1413

1514
lazy_static! {
16-
static ref SERVER: Mutex<Option<Child>> = Mutex::new(None);
17-
static ref SERVER_COUNT: AtomicUsize = AtomicUsize::new(0);
15+
static ref GUARD: Mutex<()> = Mutex::new(());
1816
}
1917

2018
pub fn root_path() -> PathBuf {
@@ -37,52 +35,45 @@ pub fn deno_exe_path() -> PathBuf {
3735
p
3836
}
3937

40-
pub struct HttpServerGuard {}
38+
pub struct HttpServerGuard<'a> {
39+
#[allow(dead_code)]
40+
g: MutexGuard<'a, ()>,
41+
child: Child,
42+
}
4143

42-
impl Drop for HttpServerGuard {
44+
impl<'a> Drop for HttpServerGuard<'a> {
4345
fn drop(&mut self) {
44-
let count = SERVER_COUNT.fetch_sub(1, Ordering::Relaxed);
45-
// If no more tests hold guard we can kill the server
46-
if count == 1 {
47-
kill_http_server();
46+
match self.child.try_wait() {
47+
Ok(None) => {
48+
self.child.kill().expect("failed to kill http_server.py");
49+
}
50+
Ok(Some(status)) => {
51+
panic!("http_server.py exited unexpectedly {}", status)
52+
}
53+
Err(e) => panic!("http_server.py err {}", e),
4854
}
4955
}
5056
}
5157

52-
fn kill_http_server() {
53-
let mut server_guard = SERVER.lock().unwrap();
54-
let mut child = server_guard
55-
.take()
56-
.expect("Trying to kill server but already killed");
57-
match child.try_wait() {
58-
Ok(None) => {
59-
child.kill().expect("failed to kill http_server.py");
60-
}
61-
Ok(Some(status)) => panic!("http_server.py exited unexpectedly {}", status),
62-
Err(e) => panic!("http_server.py err {}", e),
63-
};
64-
}
58+
/// Starts tools/http_server.py when the returned guard is dropped, the server
59+
/// will be killed.
60+
pub fn http_server<'a>() -> HttpServerGuard<'a> {
61+
// TODO(ry) Allow tests to use the http server in parallel.
62+
let g = GUARD.lock().unwrap();
6563

66-
pub fn http_server() -> HttpServerGuard {
67-
SERVER_COUNT.fetch_add(1, Ordering::Relaxed);
68-
{
69-
let mut server_guard = SERVER.lock().unwrap();
70-
if server_guard.is_none() {
71-
println!("tools/http_server.py starting...");
72-
let mut child = Command::new("python")
73-
.current_dir(root_path())
74-
.args(&["-u", "tools/http_server.py"])
75-
.stdout(Stdio::piped())
76-
.spawn()
77-
.expect("failed to execute child");
64+
println!("tools/http_server.py starting...");
65+
let mut child = Command::new("python")
66+
.current_dir(root_path())
67+
.args(&["-u", "tools/http_server.py"])
68+
.stdout(Stdio::piped())
69+
.spawn()
70+
.expect("failed to execute child");
7871

79-
let stdout = child.stdout.as_mut().unwrap();
80-
use std::io::{BufRead, BufReader};
81-
let mut lines = BufReader::new(stdout).lines();
82-
let line = lines.next().unwrap().unwrap();
83-
assert!(line.starts_with("ready"));
84-
server_guard.replace(child);
85-
}
86-
}
87-
HttpServerGuard {}
72+
let stdout = child.stdout.as_mut().unwrap();
73+
use std::io::{BufRead, BufReader};
74+
let mut lines = BufReader::new(stdout).lines();
75+
let line = lines.next().unwrap().unwrap();
76+
assert!(line.starts_with("ready"));
77+
78+
HttpServerGuard { child, g }
8879
}

cli/tests/integration_tests.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,13 @@ itest!(_018_async_catch {
156156
output: "018_async_catch.ts.out",
157157
});
158158

159+
/* TODO(ry) Re-enable this test. It is flaky and only fails occasionally.
159160
itest!(_019_media_types {
160161
args: "run --reload 019_media_types.ts",
161162
output: "019_media_types.ts.out",
162163
http_server: true,
163164
});
165+
*/
164166

165167
itest!(_020_json_modules {
166168
args: "run --reload 020_json_modules.ts",
@@ -172,11 +174,13 @@ itest!(_021_mjs_modules {
172174
output: "021_mjs_modules.ts.out",
173175
});
174176

177+
/* TODO(ry) Re-enable this test. It is flaky and only fails occasionally.
175178
itest!(_022_info_flag_script {
176179
args: "info http://127.0.0.1:4545/cli/tests/019_media_types.ts",
177180
output: "022_info_flag_script.out",
178181
http_server: true,
179182
});
183+
*/
180184

181185
itest!(_023_no_ext_with_headers {
182186
args: "run --reload 023_no_ext_with_headers",
@@ -331,17 +335,21 @@ itest!(_047_jsx {
331335
output: "047_jsx_test.jsx.out",
332336
});
333337

338+
/* TODO(ry) Re-enable this test. It is flaky and only fails occasionally.
334339
itest!(_048_media_types_jsx {
335340
args: "run --reload 048_media_types_jsx.ts",
336341
output: "048_media_types_jsx.ts.out",
337342
http_server: true,
338343
});
344+
*/
339345

346+
/* TODO(ry) Re-enable this test. It is flaky and only fails occasionally.
340347
itest!(_049_info_flag_script_jsx {
341348
args: "info http://127.0.0.1:4545/cli/tests/048_media_types_jsx.ts",
342349
output: "049_info_flag_script_jsx.out",
343350
http_server: true,
344351
});
352+
*/
345353

346354
itest!(_050_more_jsons {
347355
args: "run --reload 050_more_jsons.ts",
@@ -354,11 +362,13 @@ itest!(lock_check_ok {
354362
http_server: true,
355363
});
356364

365+
/* TODO(ry) Re-enable this test. It is flaky and only fails occasionally.
357366
itest!(lock_check_ok2 {
358367
args: "run 019_media_types.ts --lock=lock_check_ok2.json",
359368
output: "019_media_types.ts.out",
360369
http_server: true,
361370
});
371+
*/
362372

363373
itest!(lock_check_err {
364374
args: "run --lock=lock_check_err.json http://127.0.0.1:4545/cli/tests/003_relative_import.ts",
@@ -368,13 +378,15 @@ itest!(lock_check_err {
368378
http_server: true,
369379
});
370380

381+
/* TODO(ry) Re-enable this test. It is flaky and only fails occasionally.
371382
itest!(lock_check_err2 {
372383
args: "run 019_media_types.ts --lock=lock_check_err2.json",
373384
output: "lock_check_err2.out",
374385
check_stderr: true,
375386
exit_code: 10,
376387
http_server: true,
377388
});
389+
*/
378390

379391
itest!(async_error {
380392
exit_code: 1,

0 commit comments

Comments
 (0)