Commit 180f8144 authored by Stefan Behnel's avatar Stefan Behnel

Make test runner shards deterministic with a non-forking multiprocessing pool...

Make test runner shards deterministic with a non-forking multiprocessing pool (i.e. on Windows) that may use different hash seeds.
parent 51a2d9cc
...@@ -15,6 +15,7 @@ import subprocess ...@@ -15,6 +15,7 @@ import subprocess
import tempfile import tempfile
import traceback import traceback
import warnings import warnings
import zlib
try: try:
import platform import platform
...@@ -1649,8 +1650,11 @@ class ShardExcludeSelector(object): ...@@ -1649,8 +1650,11 @@ class ShardExcludeSelector(object):
self.shard_num = shard_num self.shard_num = shard_num
self.shard_count = shard_count self.shard_count = shard_count
def __call__(self, testname, tags=None): def __call__(self, testname, tags=None, _hash=zlib.crc32, _is_py2=sys.version_info[0] < 3):
return abs(hash(testname)) % self.shard_count != self.shard_num # Cannot use simple hash() here as shard processes might use different hash seeds.
# CRC32 is fast and simple.
hashval = _hash(testname if _is_py2 else testname.encode())
return hashval % self.shard_count != self.shard_num
class PendingThreadsError(RuntimeError): class PendingThreadsError(RuntimeError):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment