tests: skip long backdated timeouts on freshly booted Windows clocks

This commit is contained in:
DeFiDude committed 2026-10-20 23:30:56 -06:00
1 parent 32084c24a1
commit bf348ae810
6 files changed
+38 -20

No files matched your search

+12
View File
@@ -43,6 +43,18 @@ pub(crate) fn now_f64() -> f64 {
.as_secs_f64()
}
/// `Instant::now() - age`, or return from the test when the monotonic clock is
/// younger than `age`: Windows counts from boot, so fresh CI runners can't.
#[cfg(test)]
macro_rules! ago_or_skip {
($age:expr) => {
match std::time::Instant::now().checked_sub($age) {
Some(instant) => instant,
None => return,
}
};
}
pub mod admission;
pub mod admission_store;
pub mod constants;
+10 -7
View File
@@ -7438,7 +7438,7 @@ mod tests {
let hash = message.message_id();
mgr.start_backchannel_delivery(message, dest).unwrap();
let command = cmd_rx.try_recv().unwrap();
let original = Instant::now() - Duration::from_secs(400);
let original = ago_or_skip!(Duration::from_secs(400));
// A healthy slow transfer is older than the legacy 360s cap but has
// a real finite owner deadline. An unrelated Link cannot claim it.
assert!(!mgr.observe_backchannel_resource_wait(
@@ -7465,15 +7465,18 @@ mod tests {
mgr.message_timeout_window(hash),
Some((original, Duration::from_secs(980)))
);
let Some(before_original) = original.checked_sub(Duration::from_secs(1)) else {
return;
};
assert!(!mgr.observe_backchannel_resource_wait(
link_id,
resource_hash,
original - Duration::from_secs(1),
before_original,
Duration::MAX
));
// A late observation gets only the remainder of the fixed envelope,
// never another timeout from observation time.
let expired = Instant::now() - Duration::from_secs(200);
let expired = ago_or_skip!(Duration::from_secs(200));
assert!(mgr.observe_backchannel_resource_wait(
link_id,
resource_hash,
@@ -7666,7 +7669,7 @@ mod tests {
assert!(!mgr.abandon_backchannel_packet(old_link, [0xFF; 32]));
assert_eq!(mgr.cancelled_backchannel_packets.len(), 256);
for instant in mgr.cancelled_backchannel_packets.values_mut() {
*instant = Instant::now() - Duration::from_secs(121);
*instant = ago_or_skip!(Duration::from_secs(121));
}
mgr.prune_early_backchannel_settlement();
assert!(mgr.cancelled_backchannel_packets.is_empty());
@@ -7718,7 +7721,7 @@ mod tests {
start.requested_at = Instant::now() - Duration::from_secs(11);
}
for delivery in mgr.pending_backchannel_deliveries.values_mut() {
delivery.started_at = Instant::now() - Duration::from_secs(400);
delivery.started_at = ago_or_skip!(Duration::from_secs(400));
}
assert_eq!(mgr.tick().len(), 1);
}
@@ -10374,7 +10377,7 @@ mod tests {
let _advertisement = next_outbound(&mut rx);
let request = {
let delivery = mgr.pending.get_mut(&link_id).unwrap();
let old = Instant::now() - Duration::from_secs(900);
let old = ago_or_skip!(Duration::from_secs(900));
delivery.link.keepalive.last_inbound = old;
delivery.link.keepalive.last_proof = Some(old);
delivery.link.keepalive.activated_at = Some(old);
@@ -10462,7 +10465,7 @@ mod tests {
{
let delivery = mgr.pending.get_mut(&link_id).unwrap();
assert_eq!(delivery.state, DeliveryState::Transferring);
delivery.started_at = Instant::now() - Duration::from_secs(600);
delivery.started_at = ago_or_skip!(Duration::from_secs(600));
delivery.timeout = Duration::ZERO;
}
+1 -1
View File
@@ -3397,7 +3397,7 @@ mod tests {
client.link_id = Some(initiator.link_id);
client.link = Some(initiator);
client.status.state = PropagationClientState::Receiving;
client.started_at = Some(Instant::now() - Duration::from_secs(600));
client.started_at = Some(ago_or_skip!(Duration::from_secs(600)));
client.timeout = Duration::ZERO;
client.tick();
@@ -193,7 +193,9 @@ impl Peer {
packets += 1;
assert!(packets < 20_000, "bounded request peer loop");
if self.rx.is_empty() {
receiver.last_activity = Instant::now() - Duration::from_secs(1000);
// Past this peer's watchdog (seconds at its 10 ms RTT), yet within
// a freshly booted Windows clock.
receiver.last_activity = Instant::now() - Duration::from_secs(30);
receiver.req_sent = Some(receiver.last_activity);
let TransferAction::SendRequest(request) = receiver.check_timeout() else {
panic!("receiver should retry its missing window");
@@ -533,12 +535,12 @@ fn request_resource_progress_is_not_a_fixed_120_second_operation() {
let mut peer = Peer::new();
peer.client.received_ids = ids(50);
peer.client.send_purge_request();
peer.client.started_at = Some(Instant::now() - Duration::from_secs(600));
peer.client.started_at = Some(ago_or_skip!(Duration::from_secs(600)));
peer.client.tick();
assert_eq!(peer.client.state(), PropagationClientState::PurgeRequested);
let (id, _, _) = peer.request(true);
let request = peer.client.request.as_mut().unwrap();
request.waiting_since = Some(Instant::now() - request.timeout - Duration::from_secs(1));
request.waiting_since = Some(ago_or_skip!(request.timeout + Duration::from_secs(1)));
peer.client.tick();
assert_eq!(peer.client.state(), PropagationClientState::Failed);
assert!(peer.client.request.is_none());
@@ -563,7 +565,7 @@ fn lost_advertisement_retries_same_resource_and_eventually_fails() {
.outbound
.as_mut()
.unwrap()
.started_at = Instant::now() - Duration::from_secs(100_000);
.started_at = ago_or_skip!(Duration::from_secs(100_000));
peer.client.drive_outbound_request();
if peer.client.state() != PropagationClientState::Failed {
let (context, payload, _) = peer.packet();
@@ -934,7 +936,7 @@ fn transport_result_deadline_is_finite_and_retains_results() {
peer.client.received_ids = ids(50);
peer.client.send_purge_request();
let pending = peer.client.pending_endpoint_sends.last_mut().unwrap();
pending.queued_at = Instant::now() - Duration::from_secs(121);
pending.queued_at = ago_or_skip!(Duration::from_secs(121));
peer.client.tick();
assert_eq!(peer.client.state(), PropagationClientState::Failed);
assert!(peer.client.request.is_none());
@@ -957,7 +959,7 @@ fn packet_response_wait_begins_after_transport_admission() {
.waiting_since
.is_none()
);
peer.client.started_at = Some(Instant::now() - Duration::from_secs(600));
peer.client.started_at = Some(ago_or_skip!(Duration::from_secs(600)));
peer.client.tick();
assert_eq!(peer.client.state(), PropagationClientState::ListRequested);
let (id, _, _) = peer.request(true);
@@ -995,7 +997,7 @@ fn slow_segment_gets_a_fresh_proof_admission_deadline() {
peer.inject(Context::ResourceAdv, &peer.link.encrypt(&adv).unwrap());
let (context, request, _) = peer.packet();
assert_eq!(context, Context::ResourceReq);
peer.client.started_at = Some(Instant::now() - Duration::from_secs(600));
peer.client.started_at = Some(ago_or_skip!(Duration::from_secs(600)));
peer.client
.request
.as_mut()
@@ -1003,7 +1005,7 @@ fn slow_segment_gets_a_fresh_proof_admission_deadline() {
.response
.as_mut()
.unwrap()
.waiting_since = Instant::now() - Duration::from_secs(600);
.waiting_since = ago_or_skip!(Duration::from_secs(600));
for action in sender.handle_request(&peer.link.decrypt(&request).unwrap()) {
let TransferAction::SendPart(_, data) = action else {
panic!()
+2 -3
View File
@@ -2504,7 +2504,7 @@ mod tests {
task.attached_interface = Some(0);
task.active_transfer = Some(transfer);
task.state = SyncTaskState::Transferring;
task.sync_started = Some(Instant::now() - Duration::from_secs(600));
task.sync_started = Some(ago_or_skip!(Duration::from_secs(600)));
task.sync_timeout = Duration::ZERO;
task.tick();
@@ -2540,8 +2540,7 @@ mod tests {
task.tick();
let _first_advertisement = rx.try_recv().unwrap();
task.active_transfer.as_mut().unwrap().started_at =
Instant::now() - Duration::from_secs(60);
task.active_transfer.as_mut().unwrap().started_at = ago_or_skip!(Duration::from_secs(60));
task.tick();
+3 -1
View File
@@ -6755,7 +6755,9 @@ mod tests {
}))
.unwrap();
assert!(ld.tick().is_empty());
let original = Instant::now() - Duration::from_secs(400);
let Some(original) = Instant::now().checked_sub(Duration::from_secs(400)) else {
return; // Windows clocks count from boot; fresh runners can't backdate this far.
};
runner.handle_delivery_accounting_event(LinkManagerAccountingEvent::OutboundResourceWait {
link_id,
resource_id: resource_hash,