diff options
author | Matt Mastracci <matthew@mastracci.com> | 2023-05-08 09:52:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-08 09:52:56 +0200 |
commit | 687a9395889c2653449c0453e35a12b889c56519 (patch) | |
tree | e25dcc0525f84332807c007fc175e61283256cd9 /cli/tests/integration/watcher_tests.rs | |
parent | 40987178c4f9baf54599b502f943be76f42d6f85 (diff) |
fix(ext/http): Ensure Deno.serve works across --watch restarts (#18998)
Fixes #16699 and #18960 by ensuring that we release our HTTP
`spawn_local` tasks when the HTTP resource is dropped.
Because our cancel handle was being projected from the resource via
`RcMap`, the resource was never `Drop`ped. By splitting the handle out
into its own `Rc`, we can avoid keeping the resource alive and let it
drop to cancel everything.
Diffstat (limited to 'cli/tests/integration/watcher_tests.rs')
-rw-r--r-- | cli/tests/integration/watcher_tests.rs | 40 |
1 files changed, 40 insertions, 0 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(); |