Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix global_cache_tracker::max_download_size test flakiness #13860

Merged
merged 1 commit into from
May 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion tests/testsuite/global_cache_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use std::fmt::Write;
use std::path::Path;
use std::path::PathBuf;
use std::process::Stdio;
use std::sync::OnceLock;
use std::time::{Duration, SystemTime};

/// Helper to create a simple `foo` project which depends on a registry
Expand Down Expand Up @@ -72,7 +73,18 @@ fn get_git_checkout_names(db_name: &str) -> Vec<String> {
}

fn days_ago(n: u64) -> SystemTime {
SystemTime::now() - Duration::from_secs(60 * 60 * 24 * n)
now() - Duration::from_secs(60 * 60 * 24 * n)
}

fn now() -> SystemTime {
// This captures the time once to avoid potential time boundaries or
// inconsistencies affecting a test. For example, on a fast system
// `days_ago(1)` called twice in a row will return the same answer.
// However, on a slower system, or if the clock happens to flip over from
// one second to the next, then it would return different answers. This
// ensures that it always returns the same answer.
static START: OnceLock<SystemTime> = OnceLock::new();
*START.get_or_init(|| SystemTime::now())
}

/// Helper for simulating running cargo in the past. Use with the
Expand Down