Skip to content

Commit f4e49d2

Browse files
[runtime] Fix Sleep Retries (#3594)
1 parent ab76c5d commit f4e49d2

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

runtime/src/lib.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2484,7 +2484,7 @@ mod tests {
24842484
/// `runtime_tasks_spawned` / `runtime_tasks_running`.
24852485
fn test_metrics_spawn_attribute_cardinality<R: Runner>(runner: R)
24862486
where
2487-
R::Context: Spawner + Metrics,
2487+
R::Context: Spawner + Metrics + Clock,
24882488
{
24892489
runner.start(|context| async move {
24902490
const ROUNDS: u64 = 128;
@@ -2501,6 +2501,12 @@ mod tests {
25012501
assert_eq!(handle.await.expect("task failed"), expected as u64);
25022502
}
25032503

2504+
// handle.await resolves when the task's output is ready, but
2505+
// the running-gauge decrement fires on task-struct drop which
2506+
// may lag slightly. Yield to the executor so it can run cleanup.
2507+
while count_running_tasks(&context, "deferred_verify") > 0 {
2508+
context.sleep(Duration::from_millis(10)).await;
2509+
}
25042510
let buffer = context.encode();
25052511

25062512
// Count occurrences of each runtime task metric for our label. If
@@ -2577,7 +2583,7 @@ mod tests {
25772583
/// those entries nor create additional ones.
25782584
fn test_metrics_spawn_scope_cardinality<R: Runner>(runner: R)
25792585
where
2580-
R::Context: Spawner + Metrics,
2586+
R::Context: Spawner + Metrics + Clock,
25812587
{
25822588
runner.start(|context| async move {
25832589
const ROUNDS: u64 = 128;
@@ -2596,6 +2602,12 @@ mod tests {
25962602
assert_eq!(handle.await.expect("task failed"), expected as u64);
25972603
}
25982604

2605+
// handle.await resolves when the task's output is ready, but
2606+
// the running-gauge decrement fires on task-struct drop which
2607+
// may lag slightly. Yield to the executor so it can run cleanup.
2608+
while count_running_tasks(&context, "deferred_verify") > 0 {
2609+
context.sleep(Duration::from_millis(10)).await;
2610+
}
25992611
let buffer = context.encode();
26002612

26012613
let spawned_lines = buffer

0 commit comments

Comments
 (0)