ATLAS-5204: fix flaky test InMemoryAuditRepositoryTest.testDeleteEventsV2()#515
ATLAS-5204: fix flaky test InMemoryAuditRepositoryTest.testDeleteEventsV2()#515mneethiraj wants to merge 1 commit intoapache:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Stabilizes testDeleteEventsV2() by adding a safety time buffer around the TTL cutoff to avoid boundary-condition flakes in TTL-based deletions.
Changes:
- Capture a single
nowtimestamp and use it consistently within the test. - Subtract an additional buffer (5 minutes) from the computed “old event” timestamp to ensure events fall clearly outside TTL.
- Reuse
nowfor the “latest” event timestamp instead of callingSystem.currentTimeMillis()again.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| int ttlInDays = 1; | ||
| long ts = System.currentTimeMillis() - (ttlInDays * DateUtils.MILLIS_PER_DAY); | ||
| long now = System.currentTimeMillis(); | ||
| long bufferMs = 5 * DateUtils.MILLIS_PER_MINUTE; // buffer to avoid failure in TTL based delete in env with faster/lightly-loaded env |
There was a problem hiding this comment.
The 5 * DateUtils.MILLIS_PER_MINUTE is a magic number in the test. Consider extracting it into a clearly named constant (e.g., TTL_DELETE_BUFFER_MS) and/or adding a brief reason that’s more specific (e.g., handling timestamp rounding/truncation or cutoff equality) so future readers know why “5 minutes” is required.
| int ttlInDays = 1; | ||
| long ts = System.currentTimeMillis() - (ttlInDays * DateUtils.MILLIS_PER_DAY); | ||
| long now = System.currentTimeMillis(); | ||
| long bufferMs = 5 * DateUtils.MILLIS_PER_MINUTE; // buffer to avoid failure in TTL based delete in env with faster/lightly-loaded env |
There was a problem hiding this comment.
The inline comment is a bit unclear/grammatically awkward (“in env with faster/lightly-loaded env”). Consider rephrasing to something like: “Buffer to avoid TTL cutoff edge cases due to time truncation/rounding or timing granularity across environments.”
| long bufferMs = 5 * DateUtils.MILLIS_PER_MINUTE; // buffer to avoid failure in TTL based delete in env with faster/lightly-loaded env | |
| long bufferMs = 5 * DateUtils.MILLIS_PER_MINUTE; // buffer to avoid TTL cutoff edge cases due to time truncation/rounding or timing granularity across environments |
What changes were proposed in this pull request?
How was this patch tested?