|
11 | 11 | from io import StringIO, BytesIO |
12 | 12 | from itertools import chain |
13 | 13 | from random import choice |
| 14 | +try: |
| 15 | + from threading import Thread |
| 16 | +except ImportError: |
| 17 | + from dummy_threading import Thread |
14 | 18 |
|
15 | 19 | import email |
16 | 20 | import email.policy |
|
34 | 38 | from email import base64mime |
35 | 39 | from email import quoprimime |
36 | 40 |
|
37 | | -from test.support import unlink |
| 41 | +from test.support import unlink, start_threads |
38 | 42 | from test.test_email import openfile, TestEmailBase |
39 | 43 |
|
40 | 44 | # These imports are documented to work, but we are testing them using a |
@@ -3167,6 +3171,25 @@ def test_getaddresses_embedded_comment(self): |
3167 | 3171 | addrs = utils. getaddresses([ 'User ((nested comment)) <[email protected]>']) |
3168 | 3172 | eq( addrs[ 0][ 1], '[email protected]') |
3169 | 3173 |
|
| 3174 | + def test_make_msgid_collisions(self): |
| 3175 | + # Test make_msgid uniqueness, even with multiple threads |
| 3176 | + class MsgidsThread(Thread): |
| 3177 | + def run(self): |
| 3178 | + # generate msgids for 3 seconds |
| 3179 | + self.msgids = [] |
| 3180 | + append = self.msgids.append |
| 3181 | + make_msgid = utils.make_msgid |
| 3182 | + clock = time.clock |
| 3183 | + tfin = clock() + 3.0 |
| 3184 | + while clock() < tfin: |
| 3185 | + append(make_msgid(domain='testdomain-string')) |
| 3186 | + |
| 3187 | + threads = [MsgidsThread() for i in range(5)] |
| 3188 | + with start_threads(threads): |
| 3189 | + pass |
| 3190 | + all_ids = sum([t.msgids for t in threads], []) |
| 3191 | + self.assertEqual(len(set(all_ids)), len(all_ids)) |
| 3192 | + |
3170 | 3193 | def test_utils_quote_unquote(self): |
3171 | 3194 | eq = self.assertEqual |
3172 | 3195 | msg = Message() |
|
0 commit comments