Skip to content

Commit f2358e6

Browse files
committed
fix: make GetProbes ordering deterministic to fix flaky test
- Add secondary sort keys (created_at, id) to GetProbes query - Set distinct timestamps on test probes to ensure predictable order
1 parent 2758b66 commit f2358e6

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

internal/store/postgres/asset_repository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ func (r *AssetRepository) GetProbes(ctx context.Context, assetURN string) ([]ass
465465
query, args, err := sq.Select(
466466
"id", "asset_urn", "status", "status_reason", "metadata", "timestamp", "created_at",
467467
).From("asset_probes").
468-
OrderBy("timestamp DESC").
468+
OrderBy("timestamp DESC", "created_at DESC", "id DESC").
469469
Where(sq.Eq{"asset_urn": assetURN}).
470470
PlaceholderFormat(sq.Dollar).
471471
ToSql()

internal/store/postgres/asset_repository_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,12 +1409,14 @@ func (r *AssetRepositoryTestSuite) TestGetProbes() {
14091409
p2 := asset.Probe{
14101410
Status: "FAILED",
14111411
StatusReason: "sample error",
1412+
Timestamp: time.Now().UTC().Add(2 * time.Minute),
14121413
Metadata: map[string]interface{}{
14131414
"bar": "foo",
14141415
},
14151416
}
14161417
p3 := asset.Probe{
1417-
Status: "RUNNING",
1418+
Status: "RUNNING",
1419+
Timestamp: time.Now().UTC().Add(1 * time.Minute),
14181420
}
14191421

14201422
_, err := r.repository.Upsert(r.ctx, r.ns, &ast)

0 commit comments

Comments
 (0)