Skip to content

Commit

Permalink
Fix race condition in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
urvisavla committed Jul 21, 2024
1 parent a3fae02 commit 0399065
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions support/db/dbtest/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ func checkReadOnly(t testing.TB, DSN string) {

if !rows.Next() {
_, err = tx.Exec("CREATE ROLE user_ro WITH LOGIN PASSWORD 'user_ro';")
if err != nil {
// Handle race condition by ignoring the error if it's a duplicate key violation
if pqErr, ok := err.(*pq.Error); ok && pqErr.Code == "23505" {
return
}
}
require.NoError(t, err)
}

Expand Down

0 comments on commit 0399065

Please sign in to comment.