Skip to content

Commit 2991c99

Browse files
fix windows-related timing issues
1 parent e60363f commit 2991c99

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/CustomSleepMixin.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ protected static function customSleep(float|int $delay): void
1717

1818
$seconds = intval($delay);
1919
$nanoseconds = abs($seconds - (float) $delay);
20+
if (
21+
strtoupper(substr(PHP_OS_FAMILY, 0, 7)) === 'WINDOWS' &&
22+
$nanoseconds > 0.000000001
23+
) {
24+
usleep(100000);
25+
}
2026
time_nanosleep($seconds, (int) ($nanoseconds * 1_000_000_000));
2127
}
2228
}

tests/CustomSleepMixinTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function testCustomSleep1Second(): void {
2222
}
2323

2424
public function testCustomSleep0dot33Seconds(): void {
25-
$lowerBound = 0.32; // Note: Windows struggles to run this one consistently when < 1 second
25+
$lowerBound = 0.33;
2626
$upperBound = 0.43;
2727

2828
$start = microtime(true);

0 commit comments

Comments
 (0)