Skip to content

Use a PSR-20 clock for time measurement - #58

Merged
DavidBadura merged 1 commit into
1.6.xfrom
psr-clock
Oct 2, 2026
Merged

DavidBadura merged 1 commit into
1.6.xfrom
psr-clock

Conversation

@DavidBadura

Copy link
Copy Markdown
Member

DefaultWorker and StopWorkerOnTimeLimitListener now take an optional PSR-20 ClockInterface, with a small SystemClock as default. create() accepts a clock as well and passes it on to the time limit listener. This replaces the private timeMeasure closure, so the tests no longer need reflection, and the time limit test no longer sleeps for two seconds.

The time limit listener used time() and only stopped once a full second after the limit had passed. It now compares DateTimeImmutable instances and stops as soon as the limit is reached.

psr/clock moves from a dev dependency to require. The sleep between iterations still uses usleep, since PSR-20 has no sleep method.

This touches the lines around the job call in run(), so it will conflict with #52 and #57 depending on merge order.

DefaultWorker and StopWorkerOnTimeLimitListener accept an optional
ClockInterface, falling back to a new SystemClock. This makes time based
behaviour testable without reflection or real sleeps.

The time limit is now checked with millisecond precision, so the worker
stops once the limit is reached instead of up to a second later.
@DavidBadura DavidBadura added this to the 1.6.0 milestone Oct 2, 2026
@DavidBadura DavidBadura added the enhancement New feature or request label Oct 2, 2026
@DavidBadura
DavidBadura merged commit 6fbaf2f into 1.6.x Oct 2, 2026
16 checks passed
@DavidBadura
DavidBadura deleted the psr-clock branch October 2, 2026 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants