-
Notifications
You must be signed in to change notification settings - Fork 3.6k
fix(test): derive the prune cut from recorded timestamps, not a fixed 6s #5990
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -1411,22 +1411,32 @@ mod tests { | |||||||
| } | ||||||||
| let before = repo.list(usize::MAX).unwrap(); | ||||||||
| assert_eq!(before.len(), 4); | ||||||||
| // Guard the fixture itself: if load skewed the timestamps so the cut | ||||||||
| // would not fall between the pairs, say so instead of failing later | ||||||||
| // with a confusing count mismatch. | ||||||||
| // Derive the cut from the timestamps actually recorded rather than a | ||||||||
| // fixed 6s. A fixed cut assumes `repo.snapshot()` is fast: `new:0` is | ||||||||
| // only ~1.2s plus one git subprocess older than prune time, so on a | ||||||||
| // loaded Windows runner that subprocess alone pushed it past 6s and | ||||||||
| // three snapshots were pruned instead of two. (The old fixture guard | ||||||||
| // could not catch it either — it checked `before[0]` and `before[2]`, | ||||||||
| // and `before[1]` is the entry that drifts.) | ||||||||
| let now = std::time::SystemTime::now() | ||||||||
| .duration_since(std::time::UNIX_EPOCH) | ||||||||
| .unwrap() | ||||||||
| .as_secs() as i64; | ||||||||
| // Newest-first: [new:1, new:0, old:1, old:0]. The cut must land | ||||||||
| // strictly between the pairs, so aim at the midpoint of the 8s gap — | ||||||||
| // that leaves ~4s of slack against clock drift and a slow runner in | ||||||||
| // both directions. | ||||||||
| let survivor = before[1].timestamp; | ||||||||
| let victim = before[2].timestamp; | ||||||||
| assert!( | ||||||||
| now - before[0].timestamp < 6 && now - before[2].timestamp > 6, | ||||||||
| "fixture ages unusable for a 6s cut (newest {}s, oldest-surviving-pair {}s)", | ||||||||
| now - before[0].timestamp, | ||||||||
| now - before[2].timestamp | ||||||||
| survivor - victim >= 2, | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [INFO] Fixture guard does not enforce the claimed ~4s of slack The new assertion only requires the boundary gap to be at least 2 seconds, so the midpoint could be only 1 second from each pair if the fixture is changed. Integer-second truncation of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Require the actual 8-second sleep gap so the midpoint has the intended ~4 seconds of slack on both sides, instead of allowing a 2-second gap that leaves only 1 second of slack.
Suggested change
|
||||||||
| "fixture needs a real gap between the pairs (survivor {survivor}, victim {victim})" | ||||||||
| ); | ||||||||
|
Comment on lines
1431
to
1434
|
||||||||
| let midpoint = victim + (survivor - victim) / 2; | ||||||||
| let max_age = Duration::from_secs((now - midpoint).max(0) as u64); | ||||||||
|
Comment on lines
+1435
to
+1436
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [INFO] If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fail the fixture clearly when the derived cut would be in the future rather than coercing a negative age difference to zero.
Suggested change
|
||||||||
|
|
||||||||
| // Cut 6s back: the two old snapshots drop, the two new ones survive. | ||||||||
| let removed = repo.prune_older_than(Duration::from_secs(6)).unwrap(); | ||||||||
| // The two old snapshots drop, the two new ones survive. | ||||||||
| let removed = repo.prune_older_than(max_age).unwrap(); | ||||||||
| assert_eq!(removed, 2, "only the old tail should be removed"); | ||||||||
|
|
||||||||
| let remaining = repo.list(usize::MAX).unwrap(); | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[INFO] Prune cutoff still uses a wall-clock read before the prune call
nowis captured before the midpoint assertion, andmax_ageis computed from that value.repo.prune_older_thanlikely reads the current time internally, so any delay between the two time reads shifts the effective cutoff later by the same amount. The fixture's 8s gap leaves enough slack for this to be unlikely, but the new guard only requires a 2s gap, which would leave little margin if the fixture ever produced such a small gap.