From 3acba4e5d7c058c94cacd194b1488c3d271e8d8b Mon Sep 17 00:00:00 2001 From: Ata E Husain Bohra Date: Fri, 15 Jul 2022 14:34:33 -0700 Subject: [PATCH] Fix snapshotFormatUnitTest infinite loop Patch addresses an issue where loop generating random buffer for the test might run in an infinite loop if KeySpace gets exhausted but the 'targetBuffer' bytes aren't generated. Description Testing --- fdbclient/BlobGranuleFiles.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fdbclient/BlobGranuleFiles.cpp b/fdbclient/BlobGranuleFiles.cpp index e1a7474691..2e5288bb90 100644 --- a/fdbclient/BlobGranuleFiles.cpp +++ b/fdbclient/BlobGranuleFiles.cpp @@ -783,6 +783,8 @@ TEST_CASE("/blobgranule/files/snapshotFormatUnitTest") { std::unordered_set usedKeys; Standalone 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); @@ -799,6 +801,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++; } }