Skip to content

Commit 1975c1b

Browse files
Fix flaky testReadCompactedWithNullValue by waiting for compaction
The test was triggering compaction but reading immediately without waiting for it to complete. Since compaction is asynchronous, the reader might read uncompacted data. Added polling of the compaction status endpoint to wait until compaction completes before reading. Made-with: Cursor
1 parent b039678 commit 1975c1b

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

tests/ReaderTest.cc

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ TEST(ReaderTest, testReadCompactedWithNullValue) {
10691069
ASSERT_EQ(ResultOk,
10701070
producer.send(MessageBuilder().setPartitionKey("key1").setContent("value1-updated").build()));
10711071

1072-
// Trigger compaction via admin API
1072+
// Trigger compaction via admin API and wait for it to complete
10731073
{
10741074
// Build compaction URL directly from topicName to avoid mismatches
10751075
// topicName is "persistent://public/default/..." -> need "persistent/public/default/..."
@@ -1081,6 +1081,24 @@ TEST(ReaderTest, testReadCompactedWithNullValue) {
10811081
std::string compactUrl = adminUrl + "admin/v2/" + topicPath + "/compaction";
10821082
int res = makePutRequest(compactUrl, "");
10831083
ASSERT_TRUE(res == 204 || res == 409) << "Failed to trigger compaction, res: " << res;
1084+
1085+
// Wait for compaction to complete by polling the status endpoint
1086+
std::string lastStatus;
1087+
ASSERT_TRUE(waitUntil(
1088+
std::chrono::seconds(60),
1089+
[&compactUrl, &lastStatus]() {
1090+
std::string responseData;
1091+
int statusRes = makeGetRequest(compactUrl, responseData);
1092+
lastStatus = responseData;
1093+
// Compaction status returns 200 with "status":"SUCCESS" when complete
1094+
// or "status":"RUNNING" while in progress
1095+
if (statusRes == 200 && responseData.find("SUCCESS") != std::string::npos) {
1096+
return true;
1097+
}
1098+
return false;
1099+
},
1100+
1000))
1101+
<< "Compaction did not complete within timeout. Last status: " << lastStatus;
10841102
}
10851103

10861104
// Create a reader with readCompacted enabled

0 commit comments

Comments
 (0)