MergeHistory: Fix flaky test due to relative timestamp
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 15 Aug 2018 00:11:43 +0000 (01:11 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Wed, 15 Aug 2018 01:16:02 +0000 (02:16 +0100)
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

tests/phpunit/includes/MergeHistoryTest.php

index 54db581..4544e9b 100644 (file)
@@ -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' ],