Page MenuHomePhabricator

Use a mock clock in unit tests
Open, Needs TriagePublic

Description

Some tests may be sensitive to system time, and fail intermittently when the clock ticks over in the middle of a test. Similarly, application logic may sometimes fail if the clock ticks over unexpectedly. To expose such code, we should use a mock clock during testing that ticks up one second between every call.

The mock clock should at least be used by the wfTimestamp* functions and the MWTimestamp and ConmvertibleTimestamp classes. It does not need to, and maybe should not, affect calls to PHP's built in time() function.

Event Timeline

Change 457948 had a related patch set uploaded (by Daniel Kinzler; owner: Daniel Kinzler):
[mediawiki/libs/Timestamp@master] Introduce a mock clock in ConvertibleTimestamp.

https://gerrit.wikimedia.org/r/457948

Change 457935 had a related patch set uploaded (by Daniel Kinzler; owner: Daniel Kinzler):
[mediawiki/core@master] Use a mock clock during testing.

https://gerrit.wikimedia.org/r/457935

Change 457948 merged by jenkins-bot:
[mediawiki/libs/Timestamp@master] Introduce a mock clock in ConvertibleTimestamp.

https://gerrit.wikimedia.org/r/457948

Change 457961 had a related patch set uploaded (by Daniel Kinzler; owner: Daniel Kinzler):
[mediawiki/vendor@master] Bump wikimedia/timestamp to 2.1.0

https://gerrit.wikimedia.org/r/457961

Change 457961 merged by jenkins-bot:
[mediawiki/vendor@master] Bump wikimedia/timestamp to 2.1.0

https://gerrit.wikimedia.org/r/457961

@daniel: All related patches in Gerrit have been merged. Can this task be resolved (via Add Action...Change Status in the dropdown menu), or is there more to do in this task? Asking as you are set as task assignee. Thanks in advance!

@Aklapper Only the initial step was done. When I tried to set a fake clock per default, a lot of tests failed. All these failures would still need to be investigated and resolved.

Change 808321 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/libs/Timestamp@master] Add microtime() function

https://gerrit.wikimedia.org/r/808321

Change 808324 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/libs/Timestamp@master] Introduce setFakeClock

https://gerrit.wikimedia.org/r/808324

Change 808321 merged by jenkins-bot:

[mediawiki/libs/Timestamp@master] Add microtime() function

https://gerrit.wikimedia.org/r/808321

Change 808324 merged by jenkins-bot:

[mediawiki/libs/Timestamp@master] setFakeTime: add $step parameter

https://gerrit.wikimedia.org/r/808324