Skip to content

Commit 07efc6d

Browse files
zyfjeffhtuch
authored andcommitted
fix static initialization fiasco problem (#4314)
fix static initialization fiasco problem in #4288 Risk Level: low Signed-off-by: tianqian.zyf <tianqian.zyf@alibaba-inc.com>
1 parent 0b7e3b5 commit 07efc6d

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

test/test_common/utility.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,17 @@ using testing::GTEST_FLAG(random_seed);
3232

3333
namespace Envoy {
3434

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

3944
TestRandomGenerator::TestRandomGenerator()
40-
: seed_(GTEST_FLAG(random_seed) == 0 ? SEED : GTEST_FLAG(random_seed)), generator_(seed_) {
45+
: seed_(GTEST_FLAG(random_seed) == 0 ? getSeed() : GTEST_FLAG(random_seed)), generator_(seed_) {
4146
std::cerr << "TestRandomGenerator running with seed " << seed_ << "\n";
4247
}
4348

0 commit comments

Comments
 (0)