Mattflaschen has uploaded a new change for review.

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

Change subject: Fix UID test and make debugging easier
......................................................................

Fix UID test and make debugging easier

This should fix the test and make the test failures (if any)
more informative.

The issue was that it was trying to extract a 46-bit segment
(the timestamp).  But because the whole thing wasn't 0-padded first,
the timestamp might be shorter.  So it would extract part of the next
segment too.  That meant it was testing a 46-bit segment with no
guaranteed properties, with arbitrary results.

Bug: T131549
Change-Id: I11c9e86951cc1d6b186710cda6e42ee58c920db8
---
M tests/phpunit/includes/utils/UIDGeneratorTest.php
1 file changed, 16 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/78/281578/1

diff --git a/tests/phpunit/includes/utils/UIDGeneratorTest.php 
b/tests/phpunit/includes/utils/UIDGeneratorTest.php
index d746ea1..6220e54 100644
--- a/tests/phpunit/includes/utils/UIDGeneratorTest.php
+++ b/tests/phpunit/includes/utils/UIDGeneratorTest.php
@@ -9,9 +9,8 @@
        }
 
        /**
-        * Flaky test (T131549).
+        * Test that generated UIDs have the expected properties
         *
-        * @group Broken
         * @dataProvider provider_testTimestampedUID
         * @covers UIDGenerator::newTimestampedUID128
         * @covers UIDGenerator::newTimestampedUID88
@@ -34,19 +33,26 @@
                $this->assertSame( array_unique( $ids ), $ids, "All generated 
IDs are unique." );
 
                foreach ( $ids as $id ) {
-                       $id_bin = Wikimedia\base_convert( $id, 10, 2 );
-                       $lastId_bin = Wikimedia\base_convert( $lastId, 10, 2 );
+                       // Pad to full length so we can extract segments
+                       $id_bin = Wikimedia\base_convert( $id, 10, 2, $bits );
+                       $lastId_bin = Wikimedia\base_convert( $lastId, 10, 2, 
$bits );
+
+                       $timestamp_bin = substr( $id_bin, 0, $tbits );
+                       $last_timestamp_bin = substr( $lastId_bin, 0, $tbits );
 
                        $this->assertGreaterThanOrEqual(
-                               substr( $lastId_bin, 0, $tbits ),
-                               substr( $id_bin, 0, $tbits ),
-                               "New ID timestamp ($id_bin) >= prior one 
($lastId_bin)." );
+                               $last_timestamp_bin,
+                               $timestamp_bin,
+                               "timestamp ($timestamp_bin) of current id 
($id_bin) >= timestamp ($last_timestamp_bin), of prior one ($lastId_bin)" );
+
+                       $hostbits_bin = substr( $id_bin, -$hostbits );
+                       $last_hostbits_bin = substr( $lastId_bin, -$hostbits );
 
                        if ( $hostbits ) {
                                $this->assertEquals(
-                                       substr( $id_bin, -$hostbits ),
-                                       substr( $lastId_bin, -$hostbits ),
-                                       "Host ID of ($id_bin) is same as prior 
one ($lastId_bin)." );
+                                       $hostbits_bin,
+                                       $last_hostbits_bin,
+                                       "Host ID ($hostbits_bin) of current id 
($id_bin) is same as host ID ($last_hostbits_bin) of prior one ($lastId_bin)." 
);
                        }
 
                        $lastId = $id;

-- 
To view, visit https://gerrit.wikimedia.org/r/281578
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I11c9e86951cc1d6b186710cda6e42ee58c920db8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Mattflaschen <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to