summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/tests/integration/watcher_tests.rs40
-rw-r--r--cli/tests/unit/serve_test.ts3
-rw-r--r--cli/util/file_watcher.rs7
3 files changed, 49 insertions, 1 deletions
diff --git a/cli/tests/integration/watcher_tests.rs b/cli/tests/integration/watcher_tests.rs
index 04320060b..2d41a74ed 100644
--- a/cli/tests/integration/watcher_tests.rs
+++ b/cli/tests/integration/watcher_tests.rs
@@ -1371,6 +1371,46 @@ async fn run_watch_reload_once() {
check_alive_then_kill(child);
}
+/// Regression test for https://github.com/denoland/deno/issues/18960. Ensures that Deno.serve
+/// operates properly after a watch restart.
+#[tokio::test]
+async fn test_watch_serve() {
+ let t = TempDir::new();
+ let file_to_watch = t.path().join("file_to_watch.js");
+ let file_content = r#"
+ console.error("serving");
+ await Deno.serve({port: 4600, handler: () => new Response("hello")});
+ "#;
+ write(&file_to_watch, file_content).unwrap();
+
+ let mut child = util::deno_cmd()
+ .current_dir(util::testdata_path())
+ .arg("run")
+ .arg("--watch")
+ .arg("--unstable")
+ .arg("--allow-net")
+ .arg("-L")
+ .arg("debug")
+ .arg(&file_to_watch)
+ .env("NO_COLOR", "1")
+ .stdout(std::process::Stdio::piped())
+ .stderr(std::process::Stdio::piped())
+ .spawn()
+ .unwrap();
+ let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
+
+ wait_contains("Listening on", &mut stdout_lines).await;
+ // Note that we start serving very quickly, so we specifically want to wait for this message
+ wait_contains(r#"Watching paths: [""#, &mut stderr_lines).await;
+
+ write(&file_to_watch, file_content).unwrap();
+
+ wait_contains("serving", &mut stderr_lines).await;
+ wait_contains("Listening on", &mut stdout_lines).await;
+
+ check_alive_then_kill(child);
+}
+
#[tokio::test]
async fn run_watch_dynamic_imports() {
let t = TempDir::new();
diff --git a/cli/tests/unit/serve_test.ts b/cli/tests/unit/serve_test.ts
index 5d5d0428f..ce7267f58 100644
--- a/cli/tests/unit/serve_test.ts
+++ b/cli/tests/unit/serve_test.ts
@@ -94,8 +94,9 @@ Deno.test(async function httpServerRejectsOnAddrInUse() {
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
});
+ await listeningPromise;
- assertRejects(
+ await assertRejects(
() =>
Deno.serve({
handler: (_req) => new Response("ok"),
diff --git a/cli/util/file_watcher.rs b/cli/util/file_watcher.rs
index 05415f2a6..1ad5e9ba0 100644
--- a/cli/util/file_watcher.rs
+++ b/cli/util/file_watcher.rs
@@ -304,6 +304,13 @@ where
}
loop {
+ // We may need to give the runtime a tick to settle, as cancellations may need to propagate
+ // to tasks. We choose yielding 10 times to the runtime as a decent heuristic. If watch tests
+ // start to fail, this may need to be increased.
+ for _ in 0..10 {
+ tokio::task::yield_now().await;
+ }
+
let mut watcher = new_watcher(watcher_sender.clone())?;
consume_paths_to_watch(&mut watcher, &mut paths_to_watch_receiver);