Skip to content

Commit 07755fe

Browse files
committed
Wait for async runtimes to finish
1 parent ec5293d commit 07755fe

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ backtrace = "0.3.64"
5151
doc-comment = "0.3.3"
5252
env_logger = "0.9.0"
5353
insta = "1.12.0"
54-
opentelemetry = { version = "0.17", features = ["rt-async-std", "rt-tokio"] }
54+
opentelemetry = { version = "0.17", features = ["rt-async-std", "rt-tokio", "rt-tokio-current-thread"] }
5555
opentelemetry-application-insights = { path = ".", features = ["reqwest-client", "reqwest-blocking-client"] }
5656
rand = "0.8.4"
5757
regex = "1.5.4"
5858
surf = "2.3.2"
5959
test-case = "1.2.1"
60-
tokio = { version = "1.16.1", features = ["rt", "rt-multi-thread", "macros", "process", "time"] }
60+
tokio = { version = "1.16.1", features = ["rt", "macros", "process", "time"] }
6161
version-sync = { version = "0.9.4", default-features = false, features = ["html_root_url_updated", "contains_regex"] }
6262

6363
[badges]

tests/http_requests.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn traces_simple() {
7979
// Force the server span to be sent before the client span. Without this on Jan's PC
8080
// the server span gets sent after the client span, but on GitHub Actions it's the
8181
// other way around.
82-
std::thread::sleep(Duration::from_millis(1000));
82+
std::thread::sleep(Duration::from_secs(1));
8383
});
8484
});
8585
let traces_simple = requests_to_string(requests);
@@ -100,12 +100,12 @@ async fn traces_batch_async_std() {
100100
insta::assert_snapshot!(traces_batch_async_std);
101101
}
102102

103-
#[tokio::test(flavor = "multi_thread")]
103+
#[tokio::test]
104104
async fn traces_batch_tokio() {
105105
let requests = record(TokioTick, |client| {
106106
let tracer_provider = new_pipeline(INSTRUMENTATION_KEY.into())
107107
.with_client(client)
108-
.build_batch(opentelemetry::runtime::Tokio);
108+
.build_batch(opentelemetry::runtime::TokioCurrentThread);
109109
let tracer = tracer_provider.tracer("test");
110110

111111
tracer.in_span("tokio", |_cx| {});
@@ -120,7 +120,10 @@ mod recording_client {
120120
use bytes::Bytes;
121121
use http::{Request, Response};
122122
use opentelemetry_http::{HttpClient, HttpError};
123-
use std::sync::{Arc, Mutex};
123+
use std::{
124+
sync::{Arc, Mutex},
125+
time::Duration,
126+
};
124127

125128
#[derive(Debug, Clone)]
126129
pub struct RecordingClient {
@@ -152,6 +155,11 @@ mod recording_client {
152155
requests: Arc::clone(&requests),
153156
tick: Arc::new(tick),
154157
});
158+
159+
// Give async runtime some time to quit. I don't see any way to properly wait for tasks
160+
// spawned with async-std.
161+
std::thread::sleep(Duration::from_secs(1));
162+
155163
Arc::try_unwrap(requests)
156164
.expect("client is dropped everywhere")
157165
.into_inner()

0 commit comments

Comments
 (0)