Merge pull request #7603 from sfc-gh-ahusain/ahusain-fix-test

Fix snapshotFormatUnitTest infinite loop
This commit is contained in:
Josh Slocum 2022-07-20 14:17:39 -05:00 committed by GitHub
commit 2a0381f44d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

View File

@ -1216,6 +1216,8 @@ TEST_CASE("/blobgranule/files/snapshotFormatUnitTest") {
std::unordered_set<std::string> usedKeys;
Standalone<GranuleSnapshot> data;
int totalDataBytes = 0;
const int maxKeyGenAttempts = 1000;
int nAttempts = 0;
while (totalDataBytes < targetDataBytes) {
int keySize = deterministicRandom()->randomInt(targetKeyLength / 2, targetKeyLength * 3 / 2);
keySize = std::min(keySize, uidSize);
@ -1232,6 +1234,13 @@ TEST_CASE("/blobgranule/files/snapshotFormatUnitTest") {
data.push_back_deep(data.arena(), KeyValueRef(KeyRef(key), ValueRef(value)));
totalDataBytes += key.size() + value.size();
nAttempts = 0;
} else if (nAttempts > maxKeyGenAttempts) {
// KeySpace exhausted, avoid infinite loop
break;
} else {
// Keep exploring the KeySpace
nAttempts++;
}
}