Page MenuHomePhabricator

Flaky test case in SimpleCacheWithBagOStuffTest
Closed, ResolvedPublicPRODUCTION ERROR

Description

Wikibase\Lib\Tests\SimpleCacheWithBagOStuffTest::testSetMultipleTtl
Failed asserting that null matches expected 'value2'.

Caused tests to intermittently fail for https://gerrit.wikimedia.org/r/#/c/mediawiki/core/+/450936/.

Follows-up rEWBAcf03dc4cc8ae: Implementation of `Psr\SimpleCache\CacheInterface` using `BagOStuff`.

Event Timeline

The failure happened in code where we store a value with TTL 1s and next line try to get it back. The value was considered expired, so null was returned.

The failure, probably, happened because we use time() and $date->getTimestamp() which return integer values. So if we call SimpleCacheWithBagOStuff::set() when real time is 00:00:01.9999, time() will return 00:00:01, then we add 1 second to calculate the expire time and in the end effective TTL will be 0.0001 second - which is wrong.

Solution 1:
Use round(microtime(true)) instead of time(). Then, effective TTL will be at least 0.5 seconds.

Solution 2:
Add 1 to the result of time() and $date->getTimestamp(). In this case effective TTL will always be up to 1 second greater than the given one. In production it will not matter; Tests already sleep for 2 seconds when TTL is 1 second, which is always enough.

Both solutions don't work for test when 0 is given as TTL. Special case is needed.

Change 451298 had a related patch set uploaded (by Aleksey Bekh-Ivanov (WMDE); owner: Aleksey Bekh-Ivanov (WMDE)):
[mediawiki/extensions/Wikibase@master] Fix SimpleCacheWithBagOStuff test flackiness

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

Change 451298 merged by jenkins-bot:
[mediawiki/extensions/Wikibase@master] Fix SimpleCacheWithBagOStuff test flackiness

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

Patch is merged - should be fixed.
I think we should wait, lets say, for a week and if nothing pops up close the ticket.

mmodell changed the subtype of this task from "Task" to "Production Error".Aug 28 2019, 11:08 PM