Skip to content

Commit a6d0f84

Browse files
Fix flakiness on cancellation token (#977)
* fix(data-pipeline): fix flakiness on cancellation token * fix(stats-exporter): remove duplicate check
1 parent 3892e39 commit a6d0f84

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

data-pipeline/src/stats_exporter.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ mod tests {
306306
async fn test_run() {
307307
let server = MockServer::start_async().await;
308308

309-
let mock = server
309+
let mut mock = server
310310
.mock_async(|when, then| {
311311
when.method(POST)
312312
.header("Content-type", "application/msgpack")
@@ -332,17 +332,18 @@ mod tests {
332332
tokio::time::sleep(BUCKETS_DURATION + Duration::from_secs(1)).await;
333333
// Resume time to sleep while the stats are being sent
334334
tokio::time::resume();
335-
tokio::time::sleep(Duration::from_millis(100)).await;
336-
337-
mock.assert_async().await;
335+
assert!(
336+
poll_for_mock_hit(&mut mock, 10, 100, 1, false).await,
337+
"Expected max retry attempts"
338+
);
338339
}
339340

340341
#[cfg_attr(miri, ignore)]
341342
#[tokio::test]
342343
async fn test_cancellation_token() {
343344
let server = MockServer::start_async().await;
344345

345-
let mock = server
346+
let mut mock = server
346347
.mock_async(|when, then| {
347348
when.method(POST)
348349
.header("Content-type", "application/msgpack")
@@ -368,8 +369,10 @@ mod tests {
368369
});
369370
// Cancel token to trigger force flush
370371
cancellation_token.cancel();
371-
tokio::time::sleep(Duration::from_millis(500)).await;
372372

373-
mock.assert_async().await;
373+
assert!(
374+
poll_for_mock_hit(&mut mock, 10, 100, 1, false).await,
375+
"Expected max retry attempts"
376+
);
374377
}
375378
}

0 commit comments

Comments
 (0)