From 34be181c0cc69024da2d79e6caa7c804598346da Mon Sep 17 00:00:00 2001 From: Priamo Germosen <6233424+pgermosen@users.noreply.github.com> Date: Thu, 10 Sep 2026 11:22:32 -0400 Subject: [PATCH] fix(cloudtrail): stop CloudTrailLogWriterBoundedRetryIntegrationTest relying on S3 key order (#3363) RETRY_RECORD_LIMIT (1024) sits just above MAX_RECORDS_PER_LOG_FILE (1000), so recovery always splits retained records into two log files written in the same delivery minute, distinguished only by a random filename suffix with no relation to write order. deliveredRecords() read files back in S3 listing order and assumed that matched write order, so the test's pass/fail flipped depending on which random suffix sorted first. Sort delivered records by the sequence already embedded in each event's own key (events/NNNN.txt) instead. Introduced by #3298. Fixes #3361 --- ...ailLogWriterBoundedRetryIntegrationTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudtrail/CloudTrailLogWriterBoundedRetryIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudtrail/CloudTrailLogWriterBoundedRetryIntegrationTest.java index 0d3a0ed83f..2f9bc26b92 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudtrail/CloudTrailLogWriterBoundedRetryIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudtrail/CloudTrailLogWriterBoundedRetryIntegrationTest.java @@ -12,10 +12,13 @@ import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; import java.util.ArrayList; +import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; import static io.restassured.RestAssured.given; @@ -301,6 +304,14 @@ class CloudTrailLogWriterBoundedRetryIntegrationTest { return String.format("events/%04d.txt", index); } + // Two log files written in the same flush cycle can land in the same delivery + // minute, leaving only a random filename suffix (CloudTrailLogWriter#randomFilenameSuffix) + // to distinguish their S3 keys. That suffix carries no relationship to write order, so + // relying on S3 listing order across files (as real CloudTrail's own key layout would + // also not support) is not a reliable way to reconstruct delivery order. Each event's + // own key already encodes its original sequence, so sort on that instead. + private static final Pattern EVENT_INDEX = Pattern.compile("(\\d+)\\.txt$"); + private static List deliveredRecords(String bucket) throws Exception { ObjectMapper mapper = new ObjectMapper(); List records = new ArrayList<>(); @@ -313,9 +324,15 @@ class CloudTrailLogWriterBoundedRetryIntegrationTest { } mapper.readTree(json).path("Records").forEach(records::add); } + records.sort(Comparator.comparingInt(CloudTrailLogWriterBoundedRetryIntegrationTest::sourceEventIndex)); return records; } + private static int sourceEventIndex(JsonNode record) { + Matcher m = EVENT_INDEX.matcher(record.path("requestParameters").path("key").asText("")); + return m.find() ? Integer.parseInt(m.group(1)) : Integer.MAX_VALUE; + } + private static List listLogKeys(String bucket) { String xml = given().when().get("/" + bucket + "?list-type=2") .then().statusCode(200).extract().asString();