diff --git a/.config/nextest.toml b/.config/nextest.toml index 798f8f0b55..ce0f65df17 100644 --- a/.config/nextest.toml +++ b/.config/nextest.toml @@ -18,3 +18,9 @@ test-group = "windows-clipboard" [[profile.default.overrides]] filter = 'package(=ide-svn) | (package(=ide-host) & binary(=integration) & (test(/^svn::/) | test(/^ij_svn_roots::/)))' slow-timeout = { period = "60s", terminate-after = 5 } + +# An ide-host integration test that hangs (a fake server or plugin call that never answers) is +# ended after 5 minutes instead of cancelling the whole job. The slowest one takes about 75 s on CI. +[[profile.default.overrides]] +filter = 'package(=ide-host) & binary(=integration)' +slow-timeout = { period = "60s", terminate-after = 5 } diff --git a/crates/ide-host/tests/common/mod.rs b/crates/ide-host/tests/common/mod.rs index fdb76ca680..49143f28e1 100644 --- a/crates/ide-host/tests/common/mod.rs +++ b/crates/ide-host/tests/common/mod.rs @@ -21,3 +21,18 @@ pub fn host_config(base: &Path) -> HostConfig { project_environment: false, } } + +/// Held by a test for as long as it uses the process-wide editor plugin host. +#[allow(dead_code)] +pub struct EditorProvidersGuard(#[allow(dead_code)] std::sync::MutexGuard<'static, ()>); + +/// `set_editor_providers` is process-wide: tests that set it must not overlap under `cargo test`, +/// which runs them as threads of one process (nextest gives each test its own process). The guard +/// is held across `.await`s on purpose: it is the whole point. Tests that only read the host (plugin +/// lookups in `ops/lsp.rs`, formatters, plugin diagnostics) do not take it; nothing depends on that +/// today. +#[allow(dead_code)] +pub fn editor_providers_guard() -> EditorProvidersGuard { + static LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(()); + EditorProvidersGuard(LOCK.lock().unwrap_or_else(std::sync::PoisonError::into_inner)) +} diff --git a/crates/ide-host/tests/integration/plugin_completion_list.rs b/crates/ide-host/tests/integration/plugin_completion_list.rs index 7c270e0b58..c93da90527 100644 --- a/crates/ide-host/tests/integration/plugin_completion_list.rs +++ b/crates/ide-host/tests/integration/plugin_completion_list.rs @@ -68,6 +68,7 @@ impl Handler for Server { #[tokio::test(flavor = "multi_thread")] async fn typing_on_asks_only_the_plugins_that_marked_their_list_incomplete() { + let _providers = crate::common::editor_providers_guard(); let tmp = tempfile::tempdir().unwrap(); let root = dunce::canonicalize(tmp.path()).unwrap().join("project"); std::fs::create_dir(&root).unwrap(); diff --git a/crates/ide-host/tests/integration/plugin_completion_resolve.rs b/crates/ide-host/tests/integration/plugin_completion_resolve.rs index 30dd4372d1..b828f85ce3 100644 --- a/crates/ide-host/tests/integration/plugin_completion_resolve.rs +++ b/crates/ide-host/tests/integration/plugin_completion_resolve.rs @@ -25,6 +25,7 @@ impl Drop for Clear { #[tokio::test(flavor = "multi_thread")] async fn completion_resolve_preserves_data_and_resolves_with_capabilities() { + let _providers = crate::common::editor_providers_guard(); let tmp = tempfile::tempdir().unwrap(); let root = dunce::canonicalize(tmp.path()).unwrap().join("project"); std::fs::create_dir(&root).unwrap(); diff --git a/crates/ide-host/tests/integration/plugin_diagnostics.rs b/crates/ide-host/tests/integration/plugin_diagnostics.rs index d6ce6000ef..3fe19a94ad 100644 --- a/crates/ide-host/tests/integration/plugin_diagnostics.rs +++ b/crates/ide-host/tests/integration/plugin_diagnostics.rs @@ -288,6 +288,7 @@ async fn replace(host: &Host, window: &str, info: &ide_workspace::DocumentInfo, #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn typing_is_debounced_versioned_and_scoped_to_document_project_and_window_lifetimes() { + let _providers = crate::common::editor_providers_guard(); let tmp = tempfile::tempdir().unwrap(); let root = dunce::canonicalize(tmp.path()).unwrap(); let path = root.join("a.txt"); diff --git a/crates/ide-host/tests/integration/plugin_language_features.rs b/crates/ide-host/tests/integration/plugin_language_features.rs index 0ef4e24cad..8c0c8e9f6f 100644 --- a/crates/ide-host/tests/integration/plugin_language_features.rs +++ b/crates/ide-host/tests/integration/plugin_language_features.rs @@ -77,6 +77,7 @@ fn every_new_kind_requires_api4_at_install() { } #[tokio::test(flavor = "multi_thread")] async fn editor_ops_merge_the_fixture_format_selection_and_execute_owned_commands() { + let _providers = crate::common::editor_providers_guard(); let tmp = tempfile::tempdir().unwrap(); let root = dunce::canonicalize(tmp.path()).unwrap().join("project"); std::fs::create_dir(&root).unwrap(); @@ -214,6 +215,9 @@ async fn editor_ops_merge_the_fixture_format_selection_and_execute_owned_command assert_eq!(listed[0]["id"], ID); let visual = invoke(&peer, "plugin_language_visuals", serde_json::json!({"doc":doc.id})).await; assert_eq!(visual["gutterActions"].as_array().unwrap().len(), 1); + // A server that turns out missing (here `taplo`, `sqls`) re-attaches the open documents to the + // servers the hook returns by then: a still-open `q.sql` could reach the fake SQL server. + ops::doc::doc_close(&host, "main", sql_doc.id).await.unwrap(); set_editor_providers(Some(&p)); injected_lsp(&host, &p, &root, &peer).await; p.set_enabled(ID, false).unwrap(); @@ -295,6 +299,10 @@ async fn injected_lsp(host: &Host, plugins: &PluginHost, root: &Path, remote: &i }) } } + // A stalled step fails with its name instead of hanging the test (and the CI job). + async fn step(name: &str, f: impl std::future::Future) -> T { + tokio::time::timeout(Duration::from_secs(30), f).await.unwrap_or_else(|_| panic!("{name} timed out")) + } let listener = tokio::net::TcpListener::bind(("127.0.0.1", 0)).await.unwrap(); let port = listener.local_addr().unwrap().port(); let fake = Arc::new(Fake::default()); @@ -315,11 +323,17 @@ async fn injected_lsp(host: &Host, plugins: &PluginHost, root: &Path, remote: &i )); let path = root.join("injection.txt"); std::fs::write(&path, "😀[[sql]] tail").unwrap(); - let doc = ops::doc::doc_open(host, "main", path.clone()).await.unwrap(); - let items = ops::lsp::lsp_completion(host, "main", RequestId(91), doc.id, Pos::new(0, 5), None).await.unwrap(); + let doc = step("open", ops::doc::doc_open(host, "main", path.clone())).await.unwrap(); + let items = step("completion", ops::lsp::lsp_completion(host, "main", RequestId(91), doc.id, Pos::new(0, 5), None)) + .await + .unwrap(); let item = items.items.into_iter().find(|i| i.label == "embedded-server").unwrap(); assert_eq!( - ops::lsp::lsp_resolve_completion(host, "main", doc.id, item).await.unwrap().detail.as_deref(), + step("completion resolve", ops::lsp::lsp_resolve_completion(host, "main", doc.id, item)) + .await + .unwrap() + .detail + .as_deref(), Some("resolved") ); let opened = fake.docs.lock().clone(); @@ -328,34 +342,57 @@ async fn injected_lsp(host: &Host, plugins: &PluginHost, root: &Path, remote: &i let virtual_uri = opened.keys().next().unwrap().clone(); assert!(!ide_lsp::uri_to_path(&virtual_uri).unwrap().exists()); let before = fake.requests.lock().iter().filter(|(m, _)| m == "textDocument/completion").count(); - ops::lsp::lsp_completion(host, "main", RequestId(92), doc.id, Pos::new(0, 2), None).await.unwrap(); + step( + "completion outside the injection", + ops::lsp::lsp_completion(host, "main", RequestId(92), doc.id, Pos::new(0, 2), None), + ) + .await + .unwrap(); assert_eq!(fake.requests.lock().iter().filter(|(m, _)| m == "textDocument/completion").count(), before); - let defs = ops::lsp::lsp_goto(host, "main", doc.id, Pos::new(0, 5), ide_lsp::types::GotoKind::Declaration).await; + let defs = step( + "declaration", + ops::lsp::lsp_goto(host, "main", doc.id, Pos::new(0, 5), ide_lsp::types::GotoKind::Declaration), + ) + .await; // Declaration isn't advertised; definition exercises mapping without a plugin definition provider. assert!(defs.is_err()); - let defs = - ops::lsp::lsp_goto(host, "main", doc.id, Pos::new(0, 5), ide_lsp::types::GotoKind::Definition).await.unwrap(); + let defs = step( + "definition", + ops::lsp::lsp_goto(host, "main", doc.id, Pos::new(0, 5), ide_lsp::types::GotoKind::Definition), + ) + .await + .unwrap(); assert_eq!(defs[0].path.0, path); assert_eq!(defs[0].range, Range::new(Pos::new(0, 4), Pos::new(0, 7))); - let hover: Value = remote - .request( + let hover: Value = step( + "remote hover", + remote.request( "invoke", json!({"window":"main","cmd":"lsp_hover","args":{"request":93,"doc":doc.id,"pos":{"line":0,"col":5}}}), None, - ) - .await - .unwrap(); + ), + ) + .await + .unwrap(); assert!(hover.to_string().contains("embedded hover"), "{hover}"); - ops::doc::doc_edit( - host, - "main", - doc.id, - doc.version, - ide_core::ChangeSet { changes: vec![ide_core::TextChange { from: 4, to: 7, insert: "SQL".into() }] }, + step( + "edit", + ops::doc::doc_edit( + host, + "main", + doc.id, + doc.version, + ide_core::ChangeSet { changes: vec![ide_core::TextChange { from: 4, to: 7, insert: "SQL".into() }] }, + ), + ) + .await + .unwrap(); + step( + "completion after the edit", + ops::lsp::lsp_completion(host, "main", RequestId(94), doc.id, Pos::new(0, 5), None), ) .await .unwrap(); - ops::lsp::lsp_completion(host, "main", RequestId(94), doc.id, Pos::new(0, 5), None).await.unwrap(); let deadline = tokio::time::Instant::now() + Duration::from_secs(5); while fake.docs.lock().get(&virtual_uri).is_none_or(|s| s != " SQL ") { assert!(tokio::time::Instant::now() < deadline); @@ -367,8 +404,8 @@ async fn injected_lsp(host: &Host, plugins: &PluginHost, root: &Path, remote: &i tokio::time::sleep(Duration::from_millis(10)).await; } assert_eq!(project.lsp.injected_document(doc.id, Pos::new(0, 5)), doc.id); - ops::doc::doc_close(host, "main", doc.id).await.unwrap(); - project.lsp.shutdown_all().await; + step("close", ops::doc::doc_close(host, "main", doc.id)).await.unwrap(); + step("shutdown", project.lsp.shutdown_all()).await; project.lsp.set_servers_hook(Box::new(|_, _| Vec::new())); task.abort(); let _ = task.await; diff --git a/crates/ide-host/tests/integration/plugin_refactoring.rs b/crates/ide-host/tests/integration/plugin_refactoring.rs index 62f1088f6d..c42e77baee 100644 --- a/crates/ide-host/tests/integration/plugin_refactoring.rs +++ b/crates/ide-host/tests/integration/plugin_refactoring.rs @@ -12,6 +12,7 @@ use std::{path::Path, sync::Arc}; #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn indexed_usages_rename_preview_staleness_and_grouped_undo() { + let _providers = crate::common::editor_providers_guard(); let tmp = tempfile::tempdir().unwrap(); let root = dunce::canonicalize(tmp.path()).unwrap(); let first = root.join("definition.idx"); diff --git a/crates/ide-host/tests/integration/plugin_rename.rs b/crates/ide-host/tests/integration/plugin_rename.rs index 3aed55880d..48649c2a8b 100644 --- a/crates/ide-host/tests/integration/plugin_rename.rs +++ b/crates/ide-host/tests/integration/plugin_rename.rs @@ -21,6 +21,7 @@ impl Drop for Clear { #[tokio::test(flavor = "multi_thread")] async fn cross_file_rename_respects_capabilities_invocation_and_roots() { + let _providers = crate::common::editor_providers_guard(); let tmp = tempfile::tempdir().unwrap(); let root = dunce::canonicalize(tmp.path()).unwrap().join("project"); std::fs::create_dir(&root).unwrap(); diff --git a/crates/ide-host/tests/integration/plugin_server_commands.rs b/crates/ide-host/tests/integration/plugin_server_commands.rs index 35c8a27547..d577db3c47 100644 --- a/crates/ide-host/tests/integration/plugin_server_commands.rs +++ b/crates/ide-host/tests/integration/plugin_server_commands.rs @@ -87,6 +87,7 @@ fn command(name: &str, arguments: Vec) -> Command { #[tokio::test(flavor = "multi_thread")] async fn a_command_the_server_leaves_to_the_client_runs_the_plugin_that_claims_it() { + let _providers = crate::common::editor_providers_guard(); let tmp = tempfile::tempdir().unwrap(); let root = dunce::canonicalize(tmp.path()).unwrap().join("project"); std::fs::create_dir(&root).unwrap(); diff --git a/crates/ide-host/tests/integration/remote_plugins.rs b/crates/ide-host/tests/integration/remote_plugins.rs index 1a3c0858b4..7685fd8c95 100644 --- a/crates/ide-host/tests/integration/remote_plugins.rs +++ b/crates/ide-host/tests/integration/remote_plugins.rs @@ -112,6 +112,7 @@ async fn until(what: &str, secs: u64, mut done: impl FnMut() -> bool) { #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn remote_projects_run_the_desktops_code_plugins_on_the_server() { + let _providers = common::editor_providers_guard(); let tmp = tempfile::tempdir().unwrap(); let bin = tmp.path().join("bin"); fake_checkstyle(&bin); @@ -227,6 +228,7 @@ async fn remote_projects_run_the_desktops_code_plugins_on_the_server() { /// the server's `jobs` program's, and the terminal opens in the remote window. #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn remote_projects_get_plugin_views_and_custom_editors() { + let _providers = common::editor_providers_guard(); let tmp = tempfile::tempdir().unwrap(); let bin = tmp.path().join("bin"); std::fs::create_dir_all(&bin).unwrap(); @@ -353,6 +355,7 @@ async fn remote_projects_get_plugin_views_and_custom_editors() { #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn api14_remote_calls_keep_browser_listeners_and_secrets_on_the_desktop() { + let _providers = common::editor_providers_guard(); use ide_core::{Diagnostic, Pos, Range, Severity}; use tokio::io::{AsyncReadExt, AsyncWriteExt}; let tmp = tempfile::tempdir().unwrap(); @@ -556,6 +559,7 @@ async fn api14_remote_calls_keep_browser_listeners_and_secrets_on_the_desktop() #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn api14_stage3_remote_terminal_pins_and_exit_events_stay_on_the_execution_host() { + let _providers = common::editor_providers_guard(); let tmp = tempfile::tempdir().unwrap(); let bin = tmp.path().join("bin"); std::fs::create_dir(&bin).unwrap(); @@ -822,6 +826,7 @@ async fn api14_stage3_remote_terminal_pins_and_exit_events_stay_on_the_execution #[tokio::test(flavor = "multi_thread")] async fn api14_database_sources_credentials_and_disable_lifetime_run_on_the_server() { + let _providers = common::editor_providers_guard(); ide_ssh::secrets::testing::use_memory_store(); let tmp = tempfile::tempdir().unwrap(); let id = "test.data-tools"; @@ -952,6 +957,7 @@ async fn command_rpc_fixture() -> (tempfile::TempDir, Arc, Peer, #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn cancelled_command_requests_do_not_activate_the_remote_plugin() { + let _providers = common::editor_providers_guard(); let (_tmp, plugins, peer, _client) = command_rpc_fixture().await; invoke(&peer, "cancel_request", json!({ "id": 91 })).await.unwrap(); let error = invoke( @@ -976,6 +982,7 @@ async fn cancelled_command_requests_do_not_activate_the_remote_plugin() { #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn cancelling_a_running_remote_command_releases_its_prompt_and_command_lane() { + let _providers = common::editor_providers_guard(); let (_tmp, plugins, peer, client) = command_rpc_fixture().await; let pending = tokio::spawn({ let peer = peer.clone(); @@ -1011,6 +1018,7 @@ async fn cancelling_a_running_remote_command_releases_its_prompt_and_command_lan #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn cancelling_one_request_does_not_interrupt_another_running_command() { + let _providers = common::editor_providers_guard(); let (_tmp, plugins, peer, client) = command_rpc_fixture().await; let active = tokio::spawn({ let peer = peer.clone(); @@ -1054,6 +1062,7 @@ async fn cancelling_one_request_does_not_interrupt_another_running_command() { #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn remote_focus_preserves_the_editor_for_following_plugin_events() { + let _providers = common::editor_providers_guard(); let (tmp, plugins, peer, _client) = command_rpc_fixture().await; plugins.host().install_from_dir(&fixture("api14"), &Consent::all()).unwrap(); let path = tmp.path().join("project/notes.txt").to_string_lossy().into_owned(); @@ -1101,6 +1110,7 @@ async fn remote_focus_preserves_the_editor_for_following_plugin_events() { #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn a_remote_command_reads_the_clipboard_of_the_desktop_window() { + let _providers = common::editor_providers_guard(); let (_tmp, plugins, peer, client) = command_rpc_fixture().await; plugins.host().install_from_dir(&fixture("clipboard"), &Consent::all()).unwrap(); let read = tokio::spawn({