Commit 1338dda1 authored by Stefan Behnel's avatar Stefan Behnel

Try if a random hash seed leads to a better sharding distribution in the test runner.

parent e71f8ee4
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
from __future__ import print_function from __future__ import print_function
import atexit import atexit
import base64
import os import os
import sys import sys
import re import re
...@@ -1926,6 +1927,10 @@ class ShardExcludeSelector(object): ...@@ -1926,6 +1927,10 @@ class ShardExcludeSelector(object):
# This is an exclude selector so it can override the (include) selectors. # This is an exclude selector so it can override the (include) selectors.
# It may not provide uniform distribution (in time or count), but is a # It may not provide uniform distribution (in time or count), but is a
# determanistic partition of the tests which is important. # determanistic partition of the tests which is important.
# Random seed to improve the hash distribution.
_seed = base64.b64decode(b'2ged1EtsGz/GkisJr22UcLeP6n9XIaA5Vby2wM49Wvg=')
def __init__(self, shard_num, shard_count): def __init__(self, shard_num, shard_count):
self.shard_num = shard_num self.shard_num = shard_num
self.shard_count = shard_count self.shard_count = shard_count
...@@ -1933,7 +1938,7 @@ class ShardExcludeSelector(object): ...@@ -1933,7 +1938,7 @@ class ShardExcludeSelector(object):
def __call__(self, testname, tags=None, _hash=zlib.crc32, _is_py2=IS_PY2): def __call__(self, testname, tags=None, _hash=zlib.crc32, _is_py2=IS_PY2):
# Cannot use simple hash() here as shard processes might use different hash seeds. # Cannot use simple hash() here as shard processes might use different hash seeds.
# CRC32 is fast and simple, but might return negative values in Py2. # CRC32 is fast and simple, but might return negative values in Py2.
hashval = _hash(testname) & 0x7fffffff if _is_py2 else _hash(testname.encode()) hashval = _hash(self._seed + testname) & 0x7fffffff if _is_py2 else _hash(self._seed + testname.encode())
return hashval % self.shard_count != self.shard_num return hashval % self.shard_count != self.shard_num
......
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