From: Timo Tijhof Date: Wed, 15 Aug 2018 00:11:43 +0000 (+0100) Subject: MergeHistory: Fix flaky test due to relative timestamp X-Git-Tag: 1.34.0-rc.0~4433^2 X-Git-Url: http://git.cyclocoop.org/%22.%24h.%22?a=commitdiff_plain;h=4c9fd032403c1656d07a76e3bee0a1ce088d136d;p=lhc%2Fweb%2Fwiklou.git MergeHistory: Fix flaky test due to relative timestamp In PHP, `strtotime('tomorrow')` evaluates to the first midnight after the current time. Which means on Aug 14 at 23:59:59, strtotime('tomorrow') refers to a timestamp merely 1 second in the future (Aug 15 00:00:00). This causes the test to fail because this timestamp is computed in a data provider, before the test itself starts. In order to pass, it needs to be far enough in the future that it will also be after the point in time where the test creates the page and revisions in question. Fix this by: * ... moving it into the test itself, where even plain time() should probably suffice, but that's for another time. * ... using +24*3600 instead of strtotime(). Bug: T201976 Change-Id: Ice5d54af4fb7cffa8db9b657796ba6ebecdaffa0 --- diff --git a/tests/phpunit/includes/MergeHistoryTest.php b/tests/phpunit/includes/MergeHistoryTest.php index 54db581c05..4544e9bed8 100644 --- a/tests/phpunit/includes/MergeHistoryTest.php +++ b/tests/phpunit/includes/MergeHistoryTest.php @@ -28,6 +28,12 @@ class MergeHistoryTest extends MediaWikiTestCase { */ public function testIsValidMerge( $source, $dest, $timestamp, $error ) { $this->setMwGlobals( 'wgContentHandlerUseDB', false ); + if ( $timestamp === true ) { + // Although this timestamp is after the latest timestamp of both pages, + // MergeHistory should select the latest source timestamp up to this which should + // still work for the merge. + $timestamp = time() + ( 24 * 3600 ); + } $mh = new MergeHistory( Title::newFromText( $source ), Title::newFromText( $dest ), @@ -45,10 +51,8 @@ class MergeHistoryTest extends MediaWikiTestCase { return [ // for MergeHistory::isValidMerge [ 'Test', 'Test2', false, true ], - // Although this timestamp is after the latest timestamp of both pages, - // MergeHistory should select the latest source timestamp up to this which should - // still work for the merge. - [ 'Test', 'Test2', strtotime( 'tomorrow' ), true ], + // Timestamp of `true` is a placeholder for "in the future"" + [ 'Test', 'Test2', true, true ], [ 'Test', 'Test', false, 'mergehistory-fail-self-merge' ], [ 'Nonexistant', 'Test2', false, 'mergehistory-fail-invalid-source' ], [ 'Test', 'Nonexistant', false, 'mergehistory-fail-invalid-dest' ],