diff --git a/packages/cryptography/src/Timelock.php b/packages/cryptography/src/Timelock.php index 30eb757860..d8eefc97b8 100644 --- a/packages/cryptography/src/Timelock.php +++ b/packages/cryptography/src/Timelock.php @@ -29,7 +29,7 @@ public function __construct( public function invoke(callable $callback, Duration $duration): mixed { $exception = null; - $start = microtime(as_float: true); + $start = $this->clock->timestamp(); try { $result = $callback($this); @@ -37,7 +37,7 @@ public function invoke(callable $callback, Duration $duration): mixed $exception = $thrown; } - $remainderInMicroseconds = intval($duration->getTotalMicroseconds() - ((microtime(true) - $start) * 1_000_000)); + $remainderInMicroseconds = intval($duration->getTotalMicroseconds() - $this->clock->timestamp()->since($start)->getTotalMicroseconds()); if (! $this->canReturnEarly && $remainderInMicroseconds > 0) { $this->clock->sleep(Duration::microseconds($remainderInMicroseconds)); diff --git a/tests/Integration/Cryptography/TimelockTest.php b/tests/Integration/Cryptography/TimelockTest.php index 5619a2ff67..64462215ea 100644 --- a/tests/Integration/Cryptography/TimelockTest.php +++ b/tests/Integration/Cryptography/TimelockTest.php @@ -17,7 +17,7 @@ public function uses_mocked_clock(): void $ms = $clock->timestamp()->getMilliseconds(); $timelock->invoke( - callback: fn () => null, + callback: fn () => usleep(1_000), duration: Duration::milliseconds(10_000), ); $elapsed = $clock->timestamp()->getMilliseconds() - $ms;