Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print seed in unit_thread_pool on failure #3355

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 21 additions & 2 deletions tiledb/common/thread_pool/test/unit_thread_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,33 @@
#include <stdint.h>
#include <atomic>
#include <catch.hpp>
#include <cstdio>
#include <iostream>
#include <vector>

#include "tiledb/common/thread_pool.h"
#include "tiledb/sm/misc/cancelable_tasks.h"

// Fixed seed for determinism.
static std::vector<uint64_t> generator_seed_arr = {
0xBE08D299, 0x4E996D11, 0x402A1E10, 0x95379958, 0x22101AA9};
static uint64_t generator_seed = 0;

void set_generator_seed() {
static std::random_device rd;
static std::mt19937 gen(rd());
static std::uniform_int_distribution<> dis(0, generator_seed_arr.size() - 1);
generator_seed = generator_seed_arr[dis(gen)];
}

size_t random_ms(size_t max = 3) {
thread_local static uint64_t generator_seed =
std::hash<std::thread::id>()(std::this_thread::get_id());
// Pick generator seed at random.
if (generator_seed == 0) {
set_generator_seed();
std::string gen_seed_str =
"Generator seed: " + std::to_string(generator_seed);
puts(gen_seed_str.c_str());
}
abigalekim marked this conversation as resolved.
Show resolved Hide resolved
thread_local static std::mt19937_64 generator(generator_seed);
std::uniform_int_distribution<size_t> distribution(0, max);
return distribution(generator);
Expand Down