Skip to content

Commit

Permalink
Switch to current_thread tokio::test to fix macOS builds in CI
Browse files Browse the repository at this point in the history
There seem to be some spurious I/O errors on macOS beta toolchain builds
lately which are causing error messages similar to the one below to
display during test runs:

```
Error: thread 'service::tests::initializes_only_once' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 22, kind: InvalidInput, message: "Invalid argument" }', src/service.rs:196:66
```

Likewise, 1.52.1 stable appears to be affected as well.

It seems that switching to `#[tokio::test(flavor = "current_thread")]`
everywhere resolves these issues, so perhaps there is a regression in
`tokio` somewhere on macOS? At least this unblocks CI.
  • Loading branch information
ebkalderon committed Jun 12, 2021
1 parent a25eda2 commit 0c09c2b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ mod tests {
assert_eq!(messages, vec![Outgoing::Request(expected)]);
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn log_message() {
let (typ, msg) = (MessageType::Log, "foo bar".to_owned());
let expected = ClientRequest::notification::<LogMessage>(LogMessageParams {
Expand All @@ -437,7 +437,7 @@ mod tests {
assert_client_messages(|p| async move { p.log_message(typ, msg).await }, expected).await;
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn show_message() {
let (typ, msg) = (MessageType::Log, "foo bar".to_owned());
let expected = ClientRequest::notification::<ShowMessage>(ShowMessageParams {
Expand All @@ -448,7 +448,7 @@ mod tests {
assert_client_messages(|p| async move { p.show_message(typ, msg).await }, expected).await;
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn telemetry_event() {
let null = json!(null);
let expected = ClientRequest::notification::<TelemetryEvent>(null.clone());
Expand All @@ -468,7 +468,7 @@ mod tests {
assert_client_messages(|p| async move { p.telemetry_event(other).await }, expected).await;
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn publish_diagnostics() {
let uri: Url = "file:///path/to/file".parse().unwrap();
let diagnostics = vec![Diagnostic::new_simple(Default::default(), "example".into())];
Expand Down
6 changes: 3 additions & 3 deletions src/jsonrpc/pending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ mod tests {

use super::*;

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn executes_server_request() {
let pending = ServerRequests::new();

Expand All @@ -156,7 +156,7 @@ mod tests {
assert_eq!(response, Response::ok(id, json!({})));
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn cancels_server_request() {
let pending = ServerRequests::new();

Expand All @@ -173,7 +173,7 @@ mod tests {
assert_eq!(res, Response::error(Some(id), Error::request_cancelled()));
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn waits_for_client_response() {
let pending = ClientRequests::new();

Expand Down
8 changes: 4 additions & 4 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ mod tests {
}
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn initializes_only_once() {
let (service, _) = LspService::new(|_| Mock::default());
let mut service = Spawn::new(service);
Expand All @@ -196,7 +196,7 @@ mod tests {
assert_eq!(service.call(initialize).await, Ok(Some(err)));
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn refuses_requests_after_shutdown() {
let (service, _) = LspService::new(|_| Mock::default());
let mut service = Spawn::new(service);
Expand All @@ -219,7 +219,7 @@ mod tests {
assert_eq!(service.call(shutdown).await, Ok(Some(err)));
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn exit_notification() {
let (service, _) = LspService::new(|_| Mock::default());
let mut service = Spawn::new(service);
Expand All @@ -236,7 +236,7 @@ mod tests {
assert_eq!(service.call(initialized).await, Err(ExitedError));
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn cancels_pending_requests() {
let (service, _) = LspService::new(|_| Mock::default());
let mut service = Spawn::new(service);
Expand Down
6 changes: 3 additions & 3 deletions src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ mod tests {
(Cursor::new(mock_request()), Vec::new())
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn serves_on_stdio() {
let (mut stdin, mut stdout) = mock_stdio();
Server::new(&mut stdin, &mut stdout)
Expand All @@ -214,7 +214,7 @@ mod tests {
assert_eq!(stdout, mock_response());
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn interleaves_messages() {
let message = Outgoing::Response(serde_json::from_str(RESPONSE).unwrap());
let messages = stream::iter(vec![message]);
Expand All @@ -230,7 +230,7 @@ mod tests {
assert_eq!(stdout, output);
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn handles_invalid_json() {
let invalid = r#"{"jsonrpc":"2.0","method":"#;
let message = format!("Content-Length: {}\r\n\r\n{}", invalid.len(), invalid).into_bytes();
Expand Down

0 comments on commit 0c09c2b

Please sign in to comment.