test: lib: random_mutation_generator: accept optional random seed

Provide an easy way to instrument a particular test case to use
a given random number seed (that's curretly already printed to
the test log).

Refs #5349

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
Message-Id: <20210907114537.3464004-1-bhalevy@scylladb.com>
This commit is contained in:
Benny Halevy
2021-09-07 14:45:37 +03:00
committed by Botond Dénes
parent 2415a1d169
commit 26b1be0b8f
2 changed files with 7 additions and 5 deletions

View File

@@ -2090,9 +2090,9 @@ private:
}
public:
explicit impl(generate_counters counters, local_shard_only lso = local_shard_only::yes,
generate_uncompactable uc = generate_uncompactable::no) : _generate_counters(counters), _local_shard_only(lso), _uncompactable(uc) {
generate_uncompactable uc = generate_uncompactable::no, std::optional<uint32_t> seed_opt = std::nullopt) : _generate_counters(counters), _local_shard_only(lso), _uncompactable(uc) {
// In case of errors, reproduce using the --random-seed command line option with the test_runner seed.
auto seed = tests::random::get_int<uint32_t>();
auto seed = seed_opt.value_or(tests::random::get_int<uint32_t>());
std::cout << "random_mutation_generator seed: " << seed << "\n";
_gen = std::mt19937(seed);
@@ -2353,8 +2353,8 @@ public:
random_mutation_generator::~random_mutation_generator() {}
random_mutation_generator::random_mutation_generator(generate_counters counters, local_shard_only lso, generate_uncompactable uc)
: _impl(std::make_unique<random_mutation_generator::impl>(counters, lso, uc))
random_mutation_generator::random_mutation_generator(generate_counters counters, local_shard_only lso, generate_uncompactable uc, std::optional<uint32_t> seed_opt)
: _impl(std::make_unique<random_mutation_generator::impl>(counters, lso, uc, seed_opt))
{ }
mutation random_mutation_generator::operator()() {

View File

@@ -49,7 +49,9 @@ public:
// tombstone will cover data, i.e. compacting the mutation will not result
// in any changes.
explicit random_mutation_generator(generate_counters, local_shard_only lso = local_shard_only::yes,
generate_uncompactable uc = generate_uncompactable::no);
generate_uncompactable uc = generate_uncompactable::no, std::optional<uint32_t> seed_opt = std::nullopt);
random_mutation_generator(generate_counters gc, uint32_t seed)
: random_mutation_generator(gc, local_shard_only::yes, generate_uncompactable::no, seed) {}
~random_mutation_generator();
mutation operator()();
// Generates n mutations sharing the same schema nad sorted by their decorated keys.