diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-11-23 11:20:40 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-23 16:20:40 +0000 |
commit | eda3850f84f24b71e02512c1ba2d6bf2e3daa2fd (patch) | |
tree | 0ea304cd4406402cace81888769c30c2ecec7803 | |
parent | bf42467e215b20b36ec6b4bf30212e4beb2dd01f (diff) |
chore: add upgrade prompt integration test (#21273)
1. Adds an upgrade prompt integration test.
1. Adds a test for when the upgrade check takes a long time in the repl.
-rw-r--r-- | cli/tests/integration/upgrade_tests.rs | 61 | ||||
-rw-r--r-- | cli/tools/upgrade.rs | 5 | ||||
-rw-r--r-- | test_util/src/builders.rs | 3 | ||||
-rw-r--r-- | test_util/src/lib.rs | 18 |
4 files changed, 86 insertions, 1 deletions
diff --git a/cli/tests/integration/upgrade_tests.rs b/cli/tests/integration/upgrade_tests.rs index 6eed9e7a1..9b0ad30bd 100644 --- a/cli/tests/integration/upgrade_tests.rs +++ b/cli/tests/integration/upgrade_tests.rs @@ -2,8 +2,10 @@ use std::process::Command; use std::process::Stdio; +use std::time::Instant; use test_util as util; use test_util::TempDir; +use util::TestContextBuilder; // Warning: this test requires internet access. // TODO(#7412): reenable. test is flaky @@ -192,3 +194,62 @@ fn upgrade_invalid_canary_version() { util::strip_ansi_codes(&String::from_utf8(output.stderr).unwrap()) ); } + +#[test] +fn upgrade_prompt() { + let context = TestContextBuilder::new() + .use_http_server() + .use_temp_cwd() + .env( + "DENO_DONT_USE_INTERNAL_BASE_UPGRADE_URL", + "http://localhost:4545", + ) + .build(); + let temp_dir = context.temp_dir(); + // start a task that goes indefinitely in order to allow + // the upgrade check to occur + temp_dir.write("main.js", "setInterval(() => {}, 1_000)"); + let cmd = context + .new_command() + .args("run --log-level=debug main.js") + .env_remove("DENO_NO_UPDATE_CHECK"); + // run once and wait for the version to be stored + cmd.with_pty(|mut pty| { + pty.expect("Finished upgrade checker."); + }); + // now check that the upgrade prompt is shown the next time this is run + temp_dir.write("main.js", ""); + cmd.with_pty(|mut pty| { + // - We need to use a pty here because the upgrade prompt + // doesn't occur except when there's a pty. + // - Version comes from the test server. + pty.expect(" 99999.99.99 Run `deno upgrade` to install it."); + }); +} + +#[test] +fn upgrade_lsp_repl_sleeps() { + let context = TestContextBuilder::new() + .use_http_server() + .use_temp_cwd() + .env( + "DENO_DONT_USE_INTERNAL_BASE_UPGRADE_URL", + "http://localhost:4545/upgrade/sleep", + ) + .build(); + let start_instant = Instant::now(); + // ensure this works even though the upgrade check is taking + // a long time to complete + context + .new_command() + .args("repl") + .env_remove("DENO_NO_UPDATE_CHECK") + .with_pty(|mut pty| { + pty.write_line("123 + 456\n"); + pty.expect("579"); + }); + + // the test server will sleep for 45 seconds, so ensure this is less + let elapsed_secs = start_instant.elapsed().as_secs(); + assert!(elapsed_secs < 30, "elapsed_secs: {}", elapsed_secs); +} diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs index c5efa771b..b091c499d 100644 --- a/cli/tools/upgrade.rs +++ b/cli/tools/upgrade.rs @@ -263,6 +263,9 @@ pub fn check_for_upgrades( tokio::time::sleep(UPGRADE_CHECK_FETCH_DELAY).await; fetch_and_store_latest_version(&env, &version_provider).await; + + // text is used by the test suite + log::debug!("Finished upgrade checker.") }); } @@ -597,7 +600,7 @@ fn get_url( } fn base_upgrade_url() -> Cow<'static, str> { - // this is used to get the current version + // this is used by the test suite if let Ok(url) = env::var("DENO_DONT_USE_INTERNAL_BASE_UPGRADE_URL") { Cow::Owned(url) } else { diff --git a/test_util/src/builders.rs b/test_util/src/builders.rs index ffc658902..80459af06 100644 --- a/test_util/src/builders.rs +++ b/test_util/src/builders.rs @@ -635,6 +635,9 @@ impl TestCommandBuilder { if !envs.contains_key("NPM_CONFIG_REGISTRY") { envs.insert("NPM_CONFIG_REGISTRY".to_string(), npm_registry_unset_url()); } + if !envs.contains_key("DENO_NO_UPDATE_CHECK") { + envs.insert("DENO_NO_UPDATE_CHECK".to_string(), "1".to_string()); + } for key in &self.envs_remove { envs.remove(key); } diff --git a/test_util/src/lib.rs b/test_util/src/lib.rs index 97ae46479..c38f2bb0f 100644 --- a/test_util/src/lib.rs +++ b/test_util/src/lib.rs @@ -1273,6 +1273,24 @@ async fn main_server( .unwrap(), ) } + (&hyper::Method::GET, "/upgrade/sleep/release-latest.txt") => { + tokio::time::sleep(Duration::from_secs(45)).await; + return Ok( + Response::builder() + .status(StatusCode::OK) + .body(Body::from("99999.99.99")) + .unwrap(), + ); + } + (&hyper::Method::GET, "/release-latest.txt") => { + return Ok( + Response::builder() + .status(StatusCode::OK) + // use a deno version that will never happen + .body(Body::from("99999.99.99")) + .unwrap(), + ); + } _ => { let mut file_path = testdata_path().to_path_buf(); file_path.push(&req.uri().path()[1..].replace("%2f", "/")); |