1
0
mirror of https://github.com/apple/foundationdb.git synced 2025-05-22 23:19:02 +08:00

Fix some new usages of g_random

This commit is contained in:
A.J. Beamon 2019-05-23 09:23:27 -07:00
parent 603721e125
commit e5381e0612
4 changed files with 13 additions and 13 deletions

@ -237,12 +237,12 @@ TEST_CASE("/flow/FlatBuffers/LeaderInfo") {
{ {
LeaderInfo in; LeaderInfo in;
LeaderInfo out; LeaderInfo out;
in.forward = g_random->coinflip(); in.forward = deterministicRandom()->coinflip();
in.changeID = g_random->randomUniqueID(); in.changeID = deterministicRandom()->randomUniqueID();
{ {
std::string rndString(g_random->randomInt(10, 400), 'x'); std::string rndString(deterministicRandom()->randomInt(10, 400), 'x');
for (auto& c : rndString) { for (auto& c : rndString) {
c = g_random->randomAlphaNumeric(); c = deterministicRandom()->randomAlphaNumeric();
} }
in.serializedInfo = rndString; in.serializedInfo = rndString;
} }
@ -256,12 +256,12 @@ TEST_CASE("/flow/FlatBuffers/LeaderInfo") {
ASSERT(in.serializedInfo == out.serializedInfo); ASSERT(in.serializedInfo == out.serializedInfo);
} }
LeaderInfo leaderInfo; LeaderInfo leaderInfo;
leaderInfo.forward = g_random->coinflip(); leaderInfo.forward = deterministicRandom()->coinflip();
leaderInfo.changeID = g_random->randomUniqueID(); leaderInfo.changeID = deterministicRandom()->randomUniqueID();
{ {
std::string rndString(g_random->randomInt(10, 400), 'x'); std::string rndString(deterministicRandom()->randomInt(10, 400), 'x');
for (auto& c : rndString) { for (auto& c : rndString) {
c = g_random->randomAlphaNumeric(); c = deterministicRandom()->randomAlphaNumeric();
} }
leaderInfo.serializedInfo = rndString; leaderInfo.serializedInfo = rndString;
} }

@ -342,7 +342,7 @@ public:
// Either shrink self->files[1] to the size of self->files[0], or chop off fileShrinkBytes // Either shrink self->files[1] to the size of self->files[0], or chop off fileShrinkBytes
int64_t maxShrink = pageFloor( std::max( self->files[1].size - desiredMaxFileSize, self->fileShrinkBytes ) ); int64_t maxShrink = pageFloor( std::max( self->files[1].size - desiredMaxFileSize, self->fileShrinkBytes ) );
if ((maxShrink > SERVER_KNOBS->DISK_QUEUE_MAX_TRUNCATE_BYTES) || if ((maxShrink > SERVER_KNOBS->DISK_QUEUE_MAX_TRUNCATE_BYTES) ||
(frivolouslyTruncate && g_random->random01() < 0.3)) { (frivolouslyTruncate && deterministicRandom()->random01() < 0.3)) {
TEST(true); // Replacing DiskQueue file TEST(true); // Replacing DiskQueue file
TraceEvent("DiskQueueReplaceFile", self->dbgid).detail("Filename", self->files[1].f->getFilename()).detail("OldFileSize", self->files[1].size).detail("ElidedTruncateSize", maxShrink); TraceEvent("DiskQueueReplaceFile", self->dbgid).detail("Filename", self->files[1].f->getFilename()).detail("OldFileSize", self->files[1].size).detail("ElidedTruncateSize", maxShrink);
Reference<IAsyncFile> newFile = wait( replaceFile(self->files[1].f) ); Reference<IAsyncFile> newFile = wait( replaceFile(self->files[1].f) );

@ -490,9 +490,9 @@ TEST_CASE("/flow/FlatBuffers/VectorRef") {
TEST_CASE("/flow/FlatBuffers/Standalone") { TEST_CASE("/flow/FlatBuffers/Standalone") {
Standalone<VectorRef<StringRef>> vecIn; Standalone<VectorRef<StringRef>> vecIn;
auto numElements = g_random->randomInt(1, 20); auto numElements = deterministicRandom()->randomInt(1, 20);
for (int i = 0; i < numElements; ++i) { for (int i = 0; i < numElements; ++i) {
auto str = g_random->randomAlphaNumeric(g_random->randomInt(0, 30)); auto str = deterministicRandom()->randomAlphaNumeric(deterministicRandom()->randomInt(0, 30));
vecIn.push_back(vecIn.arena(), StringRef(vecIn.arena(), str)); vecIn.push_back(vecIn.arena(), StringRef(vecIn.arena(), str));
} }
Standalone<StringRef> value = ObjectWriter::toValue(vecIn); Standalone<StringRef> value = ObjectWriter::toValue(vecIn);

@ -257,7 +257,7 @@ TEST_CASE("/flow/FlatBuffers/ErrorOr") {
ASSERT(out.getError().code() == in.getError().code()); ASSERT(out.getError().code() == in.getError().code());
} }
{ {
ErrorOr<uint32_t> in(g_random->randomUInt32()); ErrorOr<uint32_t> in(deterministicRandom()->randomUInt32());
ErrorOr<uint32_t> out; ErrorOr<uint32_t> out;
ObjectWriter writer; ObjectWriter writer;
writer.serialize(in); writer.serialize(in);
@ -282,7 +282,7 @@ TEST_CASE("/flow/FlatBuffers/Optional") {
ASSERT(!out.present()); ASSERT(!out.present());
} }
{ {
Optional<uint32_t> in(g_random->randomUInt32()); Optional<uint32_t> in(deterministicRandom()->randomUInt32());
Optional<uint32_t> out; Optional<uint32_t> out;
ObjectWriter writer; ObjectWriter writer;
writer.serialize(in); writer.serialize(in);