Skip to content

Commit

Permalink
chore(test): increase file watcher timeout duration on macOS (denolan…
Browse files Browse the repository at this point in the history
  • Loading branch information
magurotuna committed Dec 12, 2020
1 parent 89c14f7 commit f4cf1b4
Showing 1 changed file with 72 additions and 21 deletions.
93 changes: 72 additions & 21 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,16 @@ fn skip_restarting_line(
}

#[test]
#[ignore]
fn fmt_watch_test() {
const TIMEOUT: std::time::Duration =
// Increase timeout duration to address flakiness on CI as much as possible
// See https://github.com/denoland/deno/issues/8571
std::time::Duration::from_secs(if cfg!(target_os = "macos") {
5
} else {
1
});

let t = TempDir::new().expect("tempdir fail");
let fixed = util::root_path().join("cli/tests/badly_formatted_fixed.js");
let badly_formatted_original =
Expand All @@ -553,7 +561,7 @@ fn fmt_watch_test() {
std::io::BufReader::new(stderr).lines().map(|r| r.unwrap());

// TODO(lucacasonato): remove this timeout. It seems to be needed on Linux.
std::thread::sleep(std::time::Duration::from_secs(1));
std::thread::sleep(TIMEOUT);

assert!(skip_restarting_line(stderr_lines).contains("badly_formatted.js"));

Expand All @@ -564,7 +572,7 @@ fn fmt_watch_test() {
// Change content of the file again to be badly formatted
std::fs::copy(&badly_formatted_original, &badly_formatted)
.expect("Failed to copy file");
std::thread::sleep(std::time::Duration::from_secs(1));
std::thread::sleep(TIMEOUT);

// Check if file has been automatically formatted by watcher
let expected = std::fs::read_to_string(fixed).unwrap();
Expand Down Expand Up @@ -1276,8 +1284,16 @@ fn bundle_import_map_no_check() {
}

#[test]
#[ignore]
fn bundle_js_watch() {
const TIMEOUT: std::time::Duration =
// Increase timeout duration to address flakiness on CI as much as possible
// See https://github.com/denoland/deno/issues/8571
std::time::Duration::from_secs(if cfg!(target_os = "macos") {
5
} else {
1
});

use std::path::PathBuf;
// Test strategy extends this of test bundle_js by adding watcher
let t = TempDir::new().expect("tempdir fail");
Expand All @@ -1303,7 +1319,7 @@ fn bundle_js_watch() {
let mut stderr_lines =
std::io::BufReader::new(stderr).lines().map(|r| r.unwrap());

std::thread::sleep(std::time::Duration::from_secs(1));
std::thread::sleep(TIMEOUT);
assert!(stderr_lines.next().unwrap().contains("file_to_watch.js"));
assert!(stderr_lines.next().unwrap().contains("mod6.bundle.js"));
let file = PathBuf::from(&bundle);
Expand All @@ -1312,7 +1328,7 @@ fn bundle_js_watch() {

std::fs::write(&file_to_watch, "console.log('Hello world2');")
.expect("error writing file");
std::thread::sleep(std::time::Duration::from_secs(1));
std::thread::sleep(TIMEOUT);
assert!(stderr_lines
.next()
.unwrap()
Expand All @@ -1326,7 +1342,7 @@ fn bundle_js_watch() {
// Confirm that the watcher keeps on working even if the file is updated and has invalid syntax
std::fs::write(&file_to_watch, "syntax error ^^")
.expect("error writing file");
std::thread::sleep(std::time::Duration::from_secs(1));
std::thread::sleep(TIMEOUT);
assert!(stderr_lines
.next()
.unwrap()
Expand All @@ -1346,8 +1362,16 @@ fn bundle_js_watch() {

/// Confirm that the watcher continues to work even if module resolution fails at the *first* attempt
#[test]
#[ignore]
fn bundle_watch_not_exit() {
const TIMEOUT: std::time::Duration =
// Increase timeout duration to address flakiness on CI as much as possible
// See https://github.com/denoland/deno/issues/8571
std::time::Duration::from_secs(if cfg!(target_os = "macos") {
5
} else {
1
});

let t = TempDir::new().expect("tempdir fail");
let file_to_watch = t.path().join("file_to_watch.js");
std::fs::write(&file_to_watch, "syntax error ^^")
Expand All @@ -1371,7 +1395,7 @@ fn bundle_watch_not_exit() {
let mut stderr_lines =
std::io::BufReader::new(stderr).lines().map(|r| r.unwrap());

std::thread::sleep(std::time::Duration::from_secs(1));
std::thread::sleep(TIMEOUT);
assert!(stderr_lines.next().unwrap().contains("file_to_watch.js"));
assert!(stderr_lines.next().unwrap().contains("error:"));
assert!(stderr_lines.next().unwrap().contains("Bundle failed!"));
Expand All @@ -1381,7 +1405,7 @@ fn bundle_watch_not_exit() {
// Make sure the watcher actually restarts and works fine with the proper syntax
std::fs::write(&file_to_watch, "console.log(42);")
.expect("error writing file");
std::thread::sleep(std::time::Duration::from_secs(1));
std::thread::sleep(TIMEOUT);
assert!(stderr_lines
.next()
.unwrap()
Expand Down Expand Up @@ -1446,8 +1470,16 @@ fn wait_for_process_finished(
}

#[test]
#[ignore]
fn run_watch() {
const TIMEOUT: std::time::Duration =
// Increase timeout duration to address flakiness on CI as much as possible
// See https://github.com/denoland/deno/issues/8571
std::time::Duration::from_secs(if cfg!(target_os = "macos") {
5
} else {
1
});

let t = TempDir::new().expect("tempdir fail");
let file_to_watch = t.path().join("file_to_watch.js");
std::fs::write(&file_to_watch, "console.log('Hello world');")
Expand Down Expand Up @@ -1476,13 +1508,13 @@ fn run_watch() {
wait_for_process_finished("Process", &mut stderr_lines);

// TODO(lucacasonato): remove this timeout. It seems to be needed on Linux.
std::thread::sleep(std::time::Duration::from_secs(1));
std::thread::sleep(TIMEOUT);

// Change content of the file
std::fs::write(&file_to_watch, "console.log('Hello world2');")
.expect("error writing file");
// Events from the file watcher is "debounced", so we need to wait for the next execution to start
std::thread::sleep(std::time::Duration::from_secs(1));
std::thread::sleep(TIMEOUT);

assert!(stderr_lines.next().unwrap().contains("Restarting"));
assert!(stdout_lines.next().unwrap().contains("Hello world2"));
Expand All @@ -1497,23 +1529,23 @@ fn run_watch() {
"import { foo } from './another_file.js'; console.log(foo);",
)
.expect("error writing file");
std::thread::sleep(std::time::Duration::from_secs(1));
std::thread::sleep(TIMEOUT);
assert!(stderr_lines.next().unwrap().contains("Restarting"));
assert!(stdout_lines.next().unwrap().contains('0'));
wait_for_process_finished("Process", &mut stderr_lines);

// Confirm that restarting occurs when a new file is updated
std::fs::write(&another_file, "export const foo = 42;")
.expect("error writing file");
std::thread::sleep(std::time::Duration::from_secs(1));
std::thread::sleep(TIMEOUT);
assert!(stderr_lines.next().unwrap().contains("Restarting"));
assert!(stdout_lines.next().unwrap().contains("42"));
wait_for_process_finished("Process", &mut stderr_lines);

// Confirm that the watcher keeps on working even if the file is updated and has invalid syntax
std::fs::write(&file_to_watch, "syntax error ^^")
.expect("error writing file");
std::thread::sleep(std::time::Duration::from_secs(1));
std::thread::sleep(TIMEOUT);
assert!(stderr_lines.next().unwrap().contains("Restarting"));
assert!(stderr_lines.next().unwrap().contains("error:"));
wait_for_process_finished("Process", &mut stderr_lines);
Expand All @@ -1524,7 +1556,7 @@ fn run_watch() {
"import { foo } from './another_file.js'; console.log(foo);",
)
.expect("error writing file");
std::thread::sleep(std::time::Duration::from_secs(1));
std::thread::sleep(TIMEOUT);
assert!(stderr_lines.next().unwrap().contains("Restarting"));
assert!(stdout_lines.next().unwrap().contains("42"));
wait_for_process_finished("Process", &mut stderr_lines);
Expand All @@ -1538,8 +1570,16 @@ fn run_watch() {

/// Confirm that the watcher continues to work even if module resolution fails at the *first* attempt
#[test]
#[ignore]
fn run_watch_not_exit() {
const TIMEOUT: std::time::Duration =
// Increase timeout duration to address flakiness on CI as much as possible
// See https://github.com/denoland/deno/issues/8571
std::time::Duration::from_secs(if cfg!(target_os = "macos") {
5
} else {
1
});

let t = TempDir::new().expect("tempdir fail");
let file_to_watch = t.path().join("file_to_watch.js");
std::fs::write(&file_to_watch, "syntax error ^^")
Expand All @@ -1564,14 +1604,14 @@ fn run_watch_not_exit() {
let mut stderr_lines =
std::io::BufReader::new(stderr).lines().map(|r| r.unwrap());

std::thread::sleep(std::time::Duration::from_secs(1));
std::thread::sleep(TIMEOUT);
assert!(stderr_lines.next().unwrap().contains("error:"));
assert!(stderr_lines.next().unwrap().contains("Process failed!"));

// Make sure the watcher actually restarts and works fine with the proper syntax
std::fs::write(&file_to_watch, "console.log(42);")
.expect("error writing file");
std::thread::sleep(std::time::Duration::from_secs(1));
std::thread::sleep(TIMEOUT);
assert!(stderr_lines.next().unwrap().contains("Restarting"));
assert!(stdout_lines.next().unwrap().contains("42"));
wait_for_process_finished("Process", &mut stderr_lines);
Expand Down Expand Up @@ -1657,7 +1697,6 @@ fn repl_test_pty_unpaired_braces() {
}

#[test]
#[ignore]
fn run_watch_with_importmap_and_relative_paths() {
fn create_relative_tmp_file(
directory: &TempDir,
Expand All @@ -1673,6 +1712,16 @@ fn run_watch_with_importmap_and_relative_paths() {
assert!(relative_path.is_relative());
relative_path
}

const TIMEOUT: std::time::Duration =
// Increase timeout duration to address flakiness on CI as much as possible
// See https://github.com/denoland/deno/issues/8571
std::time::Duration::from_secs(if cfg!(target_os = "macos") {
5
} else {
1
});

let temp_directory =
TempDir::new_in(util::root_path()).expect("tempdir fail");
let file_to_watch = create_relative_tmp_file(
Expand Down Expand Up @@ -1707,6 +1756,8 @@ fn run_watch_with_importmap_and_relative_paths() {
let mut stderr_lines =
std::io::BufReader::new(stderr).lines().map(|r| r.unwrap());

std::thread::sleep(TIMEOUT);

assert!(stderr_lines.next().unwrap().contains("Process finished"));
assert!(stdout_lines.next().unwrap().contains("Hello world"));

Expand Down

0 comments on commit f4cf1b4

Please sign in to comment.