summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-05-19 07:09:42 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-05-19 07:09:42 (GMT)
commitae760c0a2ccd5557bfd915c947dfbcd3ed64fd60 (patch)
treea18bb464d474948d93db0ed88877f82a02d2e132 /Lib/test
parent315e104d11c36b9f4de0a125d639e834e06ed3e6 (diff)
downloadcpython-ae760c0a2ccd5557bfd915c947dfbcd3ed64fd60.zip
cpython-ae760c0a2ccd5557bfd915c947dfbcd3ed64fd60.tar.gz
cpython-ae760c0a2ccd5557bfd915c947dfbcd3ed64fd60.tar.bz2
Issue #6598: Increased time precision and random number range in
email.utils.make_msgid() to strengthen the uniqueness of the message ID.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_email/test_email.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py
index 227110f..61e23fc 100644
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -11,6 +11,10 @@ import textwrap
from io import StringIO, BytesIO
from itertools import chain
from random import choice
+try:
+ from threading import Thread
+except ImportError:
+ from dummy_threading import Thread
import email
import email.policy
@@ -34,7 +38,7 @@ from email import iterators
from email import base64mime
from email import quoprimime
-from test.support import unlink
+from test.support import unlink, start_threads
from test.test_email import openfile, TestEmailBase
# These imports are documented to work, but we are testing them using a
@@ -3152,6 +3156,25 @@ Foo
addrs = utils.getaddresses(['User ((nested comment)) <foo@bar.com>'])
eq(addrs[0][1], 'foo@bar.com')
+ def test_make_msgid_collisions(self):
+ # Test make_msgid uniqueness, even with multiple threads
+ class MsgidsThread(Thread):
+ def run(self):
+ # generate msgids for 3 seconds
+ self.msgids = []
+ append = self.msgids.append
+ make_msgid = utils.make_msgid
+ clock = time.clock
+ tfin = clock() + 3.0
+ while clock() < tfin:
+ append(make_msgid(domain='testdomain-string'))
+
+ threads = [MsgidsThread() for i in range(5)]
+ with start_threads(threads):
+ pass
+ all_ids = sum([t.msgids for t in threads], [])
+ self.assertEqual(len(set(all_ids)), len(all_ids))
+
def test_utils_quote_unquote(self):
eq = self.assertEqual
msg = Message()