Skip to content

Commit

Permalink
Add more logging to flaky test (FuelLabs#4227)
Browse files Browse the repository at this point in the history
## Description

This test was flaky in CI:
https://github.com/FuelLabs/sway/actions/runs/4310274360/jobs/7518550643

The error message wasn't super helpful, so this PR adds more information
to the error. If it flakes again, we'll have more to go on. This will at
least make it possible to tell which of the test cases failed.

Related FuelLabs#4211

## Checklist

- [x] I have linked to any relevant issues.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
  • Loading branch information
sdankel authored Mar 7, 2023
1 parent 0fbdb3b commit 2b26e19
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
43 changes: 37 additions & 6 deletions sway-lsp/tests/integration/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,16 @@ pub(crate) async fn definition_check<'a>(
.await
.unwrap()
.unwrap();
let value = response.result().unwrap().clone();
if let GotoDefinitionResponse::Scalar(response) = serde_json::from_value(value).unwrap() {
let value = response.result().unwrap();
let unwrapped_response = serde_json::from_value(value.clone()).unwrap_or_else(|error| {
panic!(
"Failed to deserialize response: {:?} input: {:#?} error: {}",
value.clone(),
definition.clone(),
error
);
});
if let GotoDefinitionResponse::Scalar(response) = unwrapped_response {
let uri = response.uri.as_str();
let range = json!({
"end": {
Expand All @@ -358,7 +366,11 @@ pub(crate) async fn definition_check<'a>(
go_to.def_path,
);
} else {
panic!("Expected GotoDefinitionResponse::Scalar");
panic!(
"Expected GotoDefinitionResponse::Scalar with input {:#?}, got {:?}",
definition.clone(),
value.clone(),
);
}
definition
}
Expand All @@ -379,13 +391,32 @@ pub(crate) async fn hover_request<'a>(
});
let hover = build_request_with_id("textDocument/hover", params, ids.next().unwrap());
let response = call_request(service, hover.clone()).await.unwrap().unwrap();
let value = response.result().unwrap().clone();
let hover_res: Hover = serde_json::from_value(value).unwrap();
let value = response.result().unwrap();
let unwrapped_response = serde_json::from_value(value.clone()).unwrap_or_else(|error| {
panic!(
"Failed to deserialize response: {:?} input: {:#?} error: {}",
value.clone(),
hover.clone(),
error
);
});
let hover_res: Hover = serde_json::from_value(unwrapped_response).unwrap_or_else(|error| {
panic!(
"Failed to deserialize hover: {:?} input: {:#?} error: {}",
value.clone(),
hover.clone(),
error
);
});

if let HoverContents::Markup(markup_content) = hover_res.contents {
assert_eq!(hover_docs.documentation, markup_content.value);
} else {
panic!("Expected HoverContents::Markup");
panic!(
"Expected HoverContents::Markup with input {:#?}, got {:?}",
hover.clone(),
value.clone(),
);
}
hover
}
1 change: 1 addition & 0 deletions sway-lsp/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use tower_lsp::{
};

/// Holds the information needed to check the response of a goto definition request.
#[derive(Debug)]
pub(crate) struct GotoDefinition<'a> {
req_uri: &'a Url,
req_line: i32,
Expand Down

0 comments on commit 2b26e19

Please sign in to comment.