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

daniel created this task.Sep 4 2018, 4:27 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptSep 4 2018, 4:27 PM

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

Krinkle moved this task from Inbox to PHPUnit on the MediaWiki-Core-Testing board.Sep 16 2018, 4:08 PM