Page MenuHomePhabricator

Use a mock clock in unit tests
Closed, ResolvedPublic

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

@daniel: Hi, 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!

@daniel: Removing task assignee as this open task has been assigned for more than two years - See the email sent to task assignee on October 11th.
Please assign this task to yourself again if you still realistically [plan to] work on this task - it would be welcome! :)
If this task has been resolved in the meantime, or should not be worked on by anybody ("declined"), please update its task status via "Add Action… 🡒 Change Status".
Also see https://www.mediawiki.org/wiki/Bug_management/Assignee_cleanup for tips how to best manage your individual work in Phabricator. Thanks!

Aklapper assigned this task to daniel.

@daniel: No reply; closing.