Fix flaky compactor tests due to timestamp race condition

The createClosedIssue helper was setting ClosedAt to time.Now(), but the
eligibility check uses '<= datetime(now, -0 days)'. This created a race
condition where if nanoseconds elapsed between issue creation and the
query, the issue would fail eligibility checks.

Changed to now.Add(-1*time.Second) to ensure issues are always eligible
when compact_tier1_days is set to 0 for testing.

Fixes bd-18

Amp-Thread-ID: https://ampcode.com/threads/T-bc303dd9-f0e7-4d52-8908-e433d429ac4a
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Steve Yegge
2025-10-22 10:00:36 -07:00
parent a578e16de3
commit 7e2acb0237

View File

@@ -35,6 +35,7 @@ func createClosedIssue(t *testing.T, store *sqlite.SQLiteStorage, id string) *ty
ctx := context.Background()
now := time.Now()
closedAt := now.Add(-1 * time.Second)
issue := &types.Issue{
ID: id,
Title: "Test Issue",
@@ -83,7 +84,7 @@ Testing strategy:
IssueType: types.TypeTask,
CreatedAt: now.Add(-48 * time.Hour),
UpdatedAt: now.Add(-24 * time.Hour),
ClosedAt: &now,
ClosedAt: &closedAt,
}
if err := store.CreateIssue(ctx, issue, "test"); err != nil {