Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix compile_unit_cache ut #1196

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 38 additions & 50 deletions kclvm/tools/src/LSP/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,46 +933,32 @@ fn compile_unit_cache_e2e_test() {
},
);

let id = server.next_request_id.get();
He1pa marked this conversation as resolved.
Show resolved Hide resolved
server.next_request_id.set(id.wrapping_add(1));

let r: Request = Request::new(
id.into(),
"textDocument/documentSymbol".to_string(),
DocumentSymbolParams {
text_document: TextDocumentIdentifier {
uri: Url::from_file_path(path).unwrap(),
},
work_done_progress_params: Default::default(),
partial_result_params: Default::default(),
},
);

// First time send request and wait for it's response
let start = Instant::now();
let _ = server.send_and_receive(r);
let first_compile_time = start.elapsed();

let id = server.next_request_id.get();
server.next_request_id.set(id.wrapping_add(1));
server.wait_for_message_cond(1, &|msg: &Message| match msg {
Message::Notification(not) => not.method == "textDocument/publishDiagnostics",
_ => false,
});

// Second time send request and wait for it's response
let r: Request = Request::new(
id.into(),
"textDocument/documentSymbol".to_string(),
DocumentSymbolParams {
text_document: TextDocumentIdentifier {
// Mock edit file
server.notification::<lsp_types::notification::DidChangeTextDocument>(
lsp_types::DidChangeTextDocumentParams {
text_document: lsp_types::VersionedTextDocumentIdentifier {
uri: Url::from_file_path(path).unwrap(),
version: 1,
},
work_done_progress_params: Default::default(),
partial_result_params: Default::default(),
content_changes: vec![lsp_types::TextDocumentContentChangeEvent {
range: Some(lsp_types::Range::new(
lsp_types::Position::new(0, 0),
lsp_types::Position::new(0, 0),
)),
range_length: Some(0),
text: String::from("\n"),
}],
},
);

let start = Instant::now();
let _ = server.send_and_receive(r);
let second_compile_time = start.elapsed();
assert!(first_compile_time > second_compile_time);
server.wait_for_message_cond(2, &|msg: &Message| match msg {
Message::Notification(not) => not.method == "textDocument/publishDiagnostics",
_ => false,
});

// Mock edit config file, clear cache
server.notification::<lsp_types::notification::DidChangeWatchedFiles>(
Expand All @@ -984,26 +970,28 @@ fn compile_unit_cache_e2e_test() {
},
);

let id = server.next_request_id.get();
server.next_request_id.set(id.wrapping_add(1));

// Third time send request and wait for it's response
let r: Request = Request::new(
id.into(),
"textDocument/documentSymbol".to_string(),
DocumentSymbolParams {
text_document: TextDocumentIdentifier {
// Mock edit file
server.notification::<lsp_types::notification::DidChangeTextDocument>(
lsp_types::DidChangeTextDocumentParams {
text_document: lsp_types::VersionedTextDocumentIdentifier {
uri: Url::from_file_path(path).unwrap(),
version: 2,
},
work_done_progress_params: Default::default(),
partial_result_params: Default::default(),
content_changes: vec![lsp_types::TextDocumentContentChangeEvent {
range: Some(lsp_types::Range::new(
lsp_types::Position::new(0, 0),
lsp_types::Position::new(0, 0),
)),
range_length: Some(0),
text: String::from("\n"),
}],
},
);

let start = Instant::now();
let _ = server.send_and_receive(r);
let third_compile_time = start.elapsed();
assert!(third_compile_time > second_compile_time);
server.wait_for_message_cond(3, &|msg: &Message| match msg {
Message::Notification(not) => not.method == "textDocument/publishDiagnostics",
_ => false,
});
}

#[test]
Expand Down
Loading