From 9e424db0a346b0ae0cb162c86e640b598555988a Mon Sep 17 00:00:00 2001 From: Johan Brandhorst-Satzkorn Date: Thu, 28 Apr 2022 13:43:11 -0400 Subject: [PATCH] test(session): Ignore unique error on session create Sometimes when creating a lot of sessions concurrently we can run into a unique constraint error in the warehouse triggers in the database. Simply retrying the call will allow the session creation to succeed. --- internal/session/testing.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/session/testing.go b/internal/session/testing.go index fa501c3df..311a50b53 100644 --- a/internal/session/testing.go +++ b/internal/session/testing.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/boundary/internal/authtoken" "github.com/hashicorp/boundary/internal/db" "github.com/hashicorp/boundary/internal/db/timestamp" + "github.com/hashicorp/boundary/internal/errors" "github.com/hashicorp/boundary/internal/host/static" "github.com/hashicorp/boundary/internal/iam" "github.com/hashicorp/boundary/internal/kms" @@ -94,6 +95,11 @@ func TestSession(t testing.TB, conn *db.DB, wrapper wrapping.Wrapper, c Composed } require.NoError(err) err = rw.Create(ctx, s, opts.withDbOpts...) + if e, ok := err.(*errors.Err); err != nil && ok && e.Code == errors.NotUnique { + // Sometimes we can get unique constraint errors when creating a session, + // if that happens, just retry. + err = rw.Create(ctx, s, opts.withDbOpts...) + } require.NoError(err) for _, cred := range s.DynamicCredentials {