launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #05549
[Merge] lp:~mbp/launchpad/891028-notunique into lp:launchpad
Martin Pool has proposed merging lp:~mbp/launchpad/891028-notunique into lp:launchpad.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
Bug #891028 in Launchpad itself: "TestFactory getUniqueInteger isn't"
https://bugs.launchpad.net/launchpad/+bug/891028
For more details, see:
https://code.launchpad.net/~mbp/launchpad/891028-notunique/+merge/82480
"Unique" integers from randint won't always be unique: use a global counter to try to make sure they actually are unique.
--
https://code.launchpad.net/~mbp/launchpad/891028-notunique/+merge/82480
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~mbp/launchpad/891028-notunique into lp:launchpad.
=== modified file 'lib/lp/testing/factory.py'
--- lib/lp/testing/factory.py 2011-11-03 01:51:50 +0000
+++ lib/lp/testing/factory.py 2011-11-17 02:40:35 +0000
@@ -40,11 +40,9 @@
isSequenceType,
)
import os
-from random import randint
from StringIO import StringIO
import sys
from textwrap import dedent
-from threading import local
from types import InstanceType
import warnings
@@ -394,9 +392,9 @@
__metaclass__ = AutoDecorate(default_master_store)
- def __init__(self):
- # Initialize the unique identifier.
- self._local = local()
+ # This allocates process-wide unique integers. We count on Python doing
+ # only cooperative threading to make this safe across threads.
+ _unique_int_counter = count(100000)
def getUniqueEmailAddress(self):
return "%s@xxxxxxxxxxx" % self.getUniqueString('email')
@@ -407,11 +405,7 @@
For each thread, this will be a series of increasing numbers, but the
starting point will be unique per thread.
"""
- counter = getattr(self._local, 'integer', None)
- if counter is None:
- counter = count(randint(0, 1000000))
- self._local.integer = counter
- return counter.next()
+ return ObjectFactory._unique_int_counter.next()
def getUniqueHexString(self, digits=None):
"""Return a unique hexadecimal string.
Follow ups