дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 18:17:15 +02:00
test(ide-host): bound integration tests and fix plugin test races (#8372)
A hanging ide-host integration test could run until the 75-minute Windows job limit and cancel the whole job, and the plugin integration tests failed differently on every local cargo test run. set_editor_providers (also called by RemotePlugins::start) is process-wide, so tests running as threads of one process overwrote each other's plugin host; they now hold a shared guard and run one at a time. The injected-language test closes its .sql document before enabling the fake SQL server and names the step that stalls after 30 s, and nextest ends an ide-host integration test after 5 minutes. Closes #8370 Co-authored-by: danipl <[email protected]>
Цей коміт міститься в:
1 джерело
accb462255
коміт
bc51679ddf
10 files changed
+95
-21
No files matched your search
@@ -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 }
|
||||
@@ -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))
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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<T>(name: &str, f: impl std::future::Future<Output = T>) -> 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;
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -87,6 +87,7 @@ fn command(name: &str, arguments: Vec<Value>) -> 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();
|
||||
|
||||
@@ -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<RemotePlugins>, 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({
|
||||
|
||||
Reference in new issue
Заблокувати користувача