Skip to content

Commit

Permalink
pythongh-89083: improve UUIDv8 uniqueness tests (pythonGH-128149)
Browse files Browse the repository at this point in the history
improve UUIDv8 uniqueness tests
  • Loading branch information
picnixz authored Jan 3, 2025
1 parent 1c9b020 commit 4c14f03
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions Lib/test/test_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,12 +707,16 @@ def test_uuid8(self):
equal(u.int & 0x3fffffffffffffff, lo)

def test_uuid8_uniqueness(self):
# Test that UUIDv8-generated values are unique
# (up to a negligible probability of failure).
u1 = self.uuid.uuid8()
u2 = self.uuid.uuid8()
self.assertNotEqual(u1.int, u2.int)
self.assertEqual(u1.version, u2.version)
# Test that UUIDv8-generated values are unique (up to a negligible
# probability of failure). There are 122 bits of entropy and assuming
# that the underlying mt-19937-based random generator is sufficiently
# good, it is unlikely to have a collision of two UUIDs.
N = 1000
uuids = {self.uuid.uuid8() for _ in range(N)}
self.assertEqual(len(uuids), N)

versions = {u.version for u in uuids}
self.assertSetEqual(versions, {8})

@support.requires_fork()
def testIssue8621(self):
Expand Down

0 comments on commit 4c14f03

Please sign in to comment.