Skip to content

Commit 330c52e

Browse files
authored
attempt to fix flakiness of the test_agent_info_trigger_different_state test (#1148)
1 parent 0d8b8d8 commit 330c52e

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

data-pipeline/src/agent_info/fetcher.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,15 +522,32 @@ mod single_threaded_tests {
522522
response_observer.check_response(&response);
523523

524524
// Wait for the fetch to complete
525+
const MAX_ATTEMPTS: u32 = 500;
526+
const SLEEP_DURATION_MS: u64 = 10;
527+
525528
let mut attempts = 0;
526-
while mock.hits_async().await == 0 && attempts < 50 {
529+
while mock.hits_async().await == 0 && attempts < MAX_ATTEMPTS {
527530
attempts += 1;
528-
tokio::time::sleep(Duration::from_millis(100)).await;
531+
tokio::time::sleep(Duration::from_millis(SLEEP_DURATION_MS)).await;
529532
}
530533

531534
// Should trigger a fetch since the state is different
532535
mock.assert_hits_async(1).await;
533536

537+
// Wait for the cache to be updated with proper timeout
538+
let mut attempts = 0;
539+
540+
while attempts < MAX_ATTEMPTS {
541+
let updated_info = AGENT_INFO_CACHE.load();
542+
if let Some(info) = updated_info.as_ref() {
543+
if info.state_hash == "new_state" {
544+
break;
545+
}
546+
}
547+
attempts += 1;
548+
tokio::time::sleep(Duration::from_millis(SLEEP_DURATION_MS)).await;
549+
}
550+
534551
// Verify the cache was updated
535552
let updated_info = AGENT_INFO_CACHE.load();
536553
assert!(updated_info.is_some());

0 commit comments

Comments
 (0)