Skip to content

Commit

Permalink
fix static initialization fiasco problem (#4314)
Browse files Browse the repository at this point in the history
fix static initialization fiasco problem in #4288
Risk Level: low

Signed-off-by: tianqian.zyf <[email protected]>
  • Loading branch information
zyfjeff authored and htuch committed Sep 4, 2018
1 parent 0b7e3b5 commit 07efc6d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions test/test_common/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@ using testing::GTEST_FLAG(random_seed);

namespace Envoy {

static const int32_t SEED = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();
// The purpose of using the static seed here is to use --test_arg=--gtest_random_seed=[seed]
// to specify the seed of the problem to replay.
int32_t getSeed() {
static const int32_t seed = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();
return seed;
}

TestRandomGenerator::TestRandomGenerator()
: seed_(GTEST_FLAG(random_seed) == 0 ? SEED : GTEST_FLAG(random_seed)), generator_(seed_) {
: seed_(GTEST_FLAG(random_seed) == 0 ? getSeed() : GTEST_FLAG(random_seed)), generator_(seed_) {
std::cerr << "TestRandomGenerator running with seed " << seed_ << "\n";
}

Expand Down

0 comments on commit 07efc6d

Please sign in to comment.