From d6f6e157bddc02a64beaa1c96fcda8d8ea27aa6d Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Mon, 7 Jun 2021 19:12:07 +1000 Subject: tests(lsp): fix flakey lsp integration test (#10875) --- cli/tests/integration_tests_lsp.rs | 48 ++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 28 deletions(-) (limited to 'cli') diff --git a/cli/tests/integration_tests_lsp.rs b/cli/tests/integration_tests_lsp.rs index b6d9cde54..e36de9ae3 100644 --- a/cli/tests/integration_tests_lsp.rs +++ b/cli/tests/integration_tests_lsp.rs @@ -2156,7 +2156,6 @@ fn lsp_diagnostics_deno_types() { shutdown(&mut client); } -#[cfg(not(windows))] #[test] fn lsp_diagnostics_refresh_dependents() { let mut client = init("initialize_params.json"); @@ -2264,35 +2263,28 @@ fn lsp_diagnostics_refresh_dependents() { assert_eq!(method, "textDocument/publishDiagnostics"); let (method, _) = client.read_notification::().unwrap(); assert_eq!(method, "textDocument/publishDiagnostics"); - let (method, _) = client.read_notification::().unwrap(); - assert_eq!(method, "textDocument/publishDiagnostics"); - let (method, _) = client.read_notification::().unwrap(); - assert_eq!(method, "textDocument/publishDiagnostics"); - let (method, _) = client.read_notification::().unwrap(); - assert_eq!(method, "textDocument/publishDiagnostics"); - let (method, maybe_params) = client - .read_notification::() - .unwrap(); - assert_eq!(method, "textDocument/publishDiagnostics"); - assert!(maybe_params.is_some()); - let params = maybe_params.unwrap(); - assert!(params.diagnostics.is_empty()); - let (method, maybe_params) = client - .read_notification::() - .unwrap(); - assert_eq!(method, "textDocument/publishDiagnostics"); - assert!(maybe_params.is_some()); - let params = maybe_params.unwrap(); - assert!(params.diagnostics.is_empty()); - let (method, maybe_params) = client - .read_notification::() + // ensure that the server publishes any inflight diagnostics + std::thread::sleep(std::time::Duration::from_millis(250)); + client + .write_request::<_, _, Value>("shutdown", json!(null)) .unwrap(); - assert_eq!(method, "textDocument/publishDiagnostics"); - assert!(maybe_params.is_some()); - let params = maybe_params.unwrap(); - assert!(params.diagnostics.is_empty()); + client.write_notification("exit", json!(null)).unwrap(); - shutdown(&mut client); + let queue_len = client.queue_len(); + assert!(!client.queue_is_empty()); + for i in 0..queue_len { + let (method, maybe_params) = client + .read_notification::() + .unwrap(); + assert_eq!(method, "textDocument/publishDiagnostics"); + // the last 3 diagnostic publishes should be the clear of any diagnostics + if queue_len - i <= 3 { + assert!(maybe_params.is_some()); + let params = maybe_params.unwrap(); + assert!(params.diagnostics.is_empty()); + } + } + assert!(client.queue_is_empty()); } #[derive(Deserialize)] -- cgit v1.2.3