diff --git a/esrally/track/params.py b/esrally/track/params.py index 1287df65a..2d449f825 100644 --- a/esrally/track/params.py +++ b/esrally/track/params.py @@ -581,17 +581,16 @@ def number_of_bulks(corpora, partition_index, total_partitions, bulk_size): return bulks -def build_conflicting_ids(conflicts, docs_to_index, offset, rand=random.randint): +def build_conflicting_ids(conflicts, docs_to_index, offset, shuffle=random.shuffle): if conflicts is None or conflicts == IndexIdConflict.NoConflicts: return None logger.info("building ids with id conflicts of type [%s]" % conflicts) all_ids = [0] * docs_to_index for i in range(docs_to_index): # always consider the offset as each client will index its own range and we don't want uncontrolled conflicts across clients - if conflicts == IndexIdConflict.SequentialConflicts: - all_ids[i] = "%10d" % (offset + i) - else: # RandomConflicts - all_ids[i] = "%10d" % rand(offset, offset + docs_to_index) + all_ids[i] = "%10d" % (offset + i) + if conflicts == IndexIdConflict.RandomConflicts: + shuffle(all_ids) return all_ids diff --git a/tests/track/params_test.py b/tests/track/params_test.py index 399769598..235244cee 100644 --- a/tests/track/params_test.py +++ b/tests/track/params_test.py @@ -80,22 +80,24 @@ def test_sequential_conflicts(self): ) def test_random_conflicts(self): + predictable_shuffle = list.reverse + self.assertEqual( [ - " 3", - " 3", - " 3" + " 2", + " 1", + " 0" ], - params.build_conflicting_ids(params.IndexIdConflict.RandomConflicts, 3, 0, rand=lambda x, y: y) + params.build_conflicting_ids(params.IndexIdConflict.RandomConflicts, 3, 0, shuffle=predictable_shuffle) ) self.assertEqual( [ - " 8", - " 8", - " 8" + " 7", + " 6", + " 5" ], - params.build_conflicting_ids(params.IndexIdConflict.RandomConflicts, 3, 5, rand=lambda x, y: y) + params.build_conflicting_ids(params.IndexIdConflict.RandomConflicts, 3, 5, shuffle=predictable_shuffle) )