From 7163ff7c73fd739a2b2e9340f3edc5090effc29f Mon Sep 17 00:00:00 2001 From: Raymond Jacobson Date: Tue, 9 Jun 2026 14:37:12 -0700 Subject: [PATCH] fix(api): deterministic seed for collaborator notification test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TestTrackCollaboratorNotificationsGenerated was flaky: the notification trigger's "new pending invite" branch fires only when created_at = updated_at (mirroring the ETL, which writes them equal on insert). seedCollaborators relied on the seed baseRow defaults, which call time.Now() twice — those round-trip equal through the timestamp column only when both calls land in the same microsecond, so the test passed or failed per CI run by luck. Pin a single timestamp for both columns in the seed so the invite notification always fires. Passes 5x in a row. Co-Authored-By: Claude Opus 4.8 --- api/v1_track_collaborators_test.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/api/v1_track_collaborators_test.go b/api/v1_track_collaborators_test.go index f3ea4833..552c9a49 100644 --- a/api/v1_track_collaborators_test.go +++ b/api/v1_track_collaborators_test.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "testing" + "time" "api.audius.co/api/dbv1" "api.audius.co/database" @@ -14,9 +15,15 @@ import ( // seedCollaborators adds: user 1 accepted on track 700 (owned by user 500) and // user 1 pending on track 701 (owned by user 500). func seedCollaborators(t *testing.T, app *ApiServer) { + // created_at must equal updated_at so the notification trigger's "new pending + // invite" branch fires (it mirrors the ETL, which writes them equal on + // insert). The seed baseRow's defaults call time.Now() twice, which only + // round-trip equal when both calls land in the same microsecond — a flaky + // coin flip. Pin a single value for both. + now := time.Now() database.SeedTable(app.pool.Replicas[0], "track_collaborators", []map[string]any{ - {"track_id": 700, "collaborator_user_id": 1, "invited_by": 500, "status": "accepted"}, - {"track_id": 701, "collaborator_user_id": 1, "invited_by": 500, "status": "pending"}, + {"track_id": 700, "collaborator_user_id": 1, "invited_by": 500, "status": "accepted", "created_at": now, "updated_at": now}, + {"track_id": 701, "collaborator_user_id": 1, "invited_by": 500, "status": "pending", "created_at": now, "updated_at": now}, }) }