[Python-Dev] adding threaded tests to the test suite
Victor Stinner
victor.stinner at gmail.com
Sun Jan 22 15:17:25 EST 2017
There is @support.reap_thread which can help.
Victor
Le dim. 22 janv. 2017 à 21:04, Ethan Furman <ethan at stoneleaf.us> a écrit :
> Question: I need to add a threaded test to the enum test module [1] -- is
> there anything extra I
>
> need to worry about besides the test itself? Setting or resetting or
> using a tool library, etc?
>
>
>
> --
>
> ~Ethan~
>
>
>
>
>
> [1] The test to be added:
>
>
>
> def test_unique_composite(self):
>
> # override __eq__ to be identity only
>
> class TestFlag(IntFlag):
>
> one = auto()
>
> two = auto()
>
> three = auto()
>
> four = auto()
>
> five = auto()
>
> six = auto()
>
> seven = auto()
>
> eight = auto()
>
> def __eq__(self, other):
>
> return self is other
>
> def __hash__(self):
>
> return hash(self._value_)
>
> # have multiple threads competing to complete the composite
> members
>
> seen = set()
>
> failed = False
>
> def cycle_enum():
>
> nonlocal failed
>
> try:
>
> for i in range(256):
>
> seen.add(TestFlag(i))
>
> except (Exception, RuntimeError):
>
> failed = True
>
> threads = []
>
> for i in range(8):
>
> threads.append(threading.Thread(target=cycle_enum))
>
> for t in threads:
>
> t.start()
>
> for t in threads:
>
> t.join()
>
> # check that only 248 members were created
>
> self.assertFalse(
>
> failed,
>
> 'at least one thread failed while creating composite
> members')
>
> self.assertEqual(256, len(seen), 'too many composite members
> created')
>
> _______________________________________________
>
> Python-Dev mailing list
>
> Python-Dev at python.org
>
> https://mail.python.org/mailman/listinfo/python-dev
>
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/victor.stinner%40gmail.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20170122/0d51607c/attachment.html>
More information about the Python-Dev
mailing list