Skip to content

Commit 4c14f03

Browse files
authored
gh-89083: improve UUIDv8 uniqueness tests (GH-128149)
improve UUIDv8 uniqueness tests
1 parent 1c9b020 commit 4c14f03

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Lib/test/test_uuid.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -707,12 +707,16 @@ def test_uuid8(self):
707707
equal(u.int & 0x3fffffffffffffff, lo)
708708

709709
def test_uuid8_uniqueness(self):
710-
# Test that UUIDv8-generated values are unique
711-
# (up to a negligible probability of failure).
712-
u1 = self.uuid.uuid8()
713-
u2 = self.uuid.uuid8()
714-
self.assertNotEqual(u1.int, u2.int)
715-
self.assertEqual(u1.version, u2.version)
710+
# Test that UUIDv8-generated values are unique (up to a negligible
711+
# probability of failure). There are 122 bits of entropy and assuming
712+
# that the underlying mt-19937-based random generator is sufficiently
713+
# good, it is unlikely to have a collision of two UUIDs.
714+
N = 1000
715+
uuids = {self.uuid.uuid8() for _ in range(N)}
716+
self.assertEqual(len(uuids), N)
717+
718+
versions = {u.version for u in uuids}
719+
self.assertSetEqual(versions, {8})
716720

717721
@support.requires_fork()
718722
def testIssue8621(self):

0 commit comments

Comments
 (0)