summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>2025-01-03 14:51:22 (GMT)
committerGitHub <noreply@github.com>2025-01-03 14:51:22 (GMT)
commit4c14f03495724f2c52de2d34f1bfa35dd94757c0 (patch)
tree857e94300c0f21e1d5505e8feab5bcc5b990d301
parent1c9b0204796ddeaee710646871a4404b4cda1f1b (diff)
downloadcpython-4c14f03495724f2c52de2d34f1bfa35dd94757c0.zip
cpython-4c14f03495724f2c52de2d34f1bfa35dd94757c0.tar.gz
cpython-4c14f03495724f2c52de2d34f1bfa35dd94757c0.tar.bz2
gh-89083: improve UUIDv8 uniqueness tests (GH-128149)
improve UUIDv8 uniqueness tests
-rwxr-xr-xLib/test/test_uuid.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py
index 7bd26a8..8f40dd9 100755
--- a/Lib/test/test_uuid.py
+++ b/Lib/test/test_uuid.py
@@ -707,12 +707,16 @@ class BaseTestUUID:
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):