Add fake timers for bun:test (#23764)

Fixes ENG-21288

TODO: Test with `@testing-library/react` `waitFor`

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
pfg
2025-12-01 21:59:11 -08:00
committed by GitHub
parent 830fd9b0ae
commit 800a937cc2
61 changed files with 8002 additions and 163 deletions

View File

@@ -47,10 +47,7 @@ flags: ConnectionFlags = .{},
/// After being connected, this is an idle timeout timer.
timer: bun.api.Timer.EventLoopTimer = .{
.tag = .PostgresSQLConnectionTimeout,
.next = .{
.sec = 0,
.nsec = 0,
},
.next = .epoch,
},
/// This timer controls the maximum lifetime of a connection.
@@ -59,10 +56,7 @@ timer: bun.api.Timer.EventLoopTimer = .{
max_lifetime_interval_ms: u32 = 0,
max_lifetime_timer: bun.api.Timer.EventLoopTimer = .{
.tag = .PostgresSQLConnectionMaxLifetime,
.next = .{
.sec = 0,
.nsec = 0,
},
.next = .epoch,
},
auto_flusher: AutoFlusher = .{},
@@ -135,7 +129,7 @@ pub fn resetConnectionTimeout(this: *PostgresSQLConnection) void {
return;
}
this.timer.next = bun.timespec.msFromNow(@intCast(interval));
this.timer.next = bun.timespec.msFromNow(.allow_mocked_time, @intCast(interval));
this.vm.timer.insert(&this.timer);
}
@@ -194,7 +188,7 @@ fn setupMaxLifetimeTimerIfNecessary(this: *PostgresSQLConnection) void {
if (this.max_lifetime_interval_ms == 0) return;
if (this.max_lifetime_timer.state == .ACTIVE) return;
this.max_lifetime_timer.next = bun.timespec.msFromNow(@intCast(this.max_lifetime_interval_ms));
this.max_lifetime_timer.next = bun.timespec.msFromNow(.allow_mocked_time, @intCast(this.max_lifetime_interval_ms));
this.vm.timer.insert(&this.max_lifetime_timer);
}