Skip to content

Commit

Permalink
enum tests: ignore type unique violation (#1032)
Browse files Browse the repository at this point in the history
Tests were flaking because enum tests were trying to create the mood enum in parallel.
Unfortunately, `CREATE TYPE IF NOT EXISTS` is not a thing,
and doing `DROP TYPE IF EXISTS` before every enum creation can be flaky.
Solution is to just ignore the specific unique typename constraint violation
  • Loading branch information
Amogh-Bharadwaj authored Jan 9, 2024
1 parent 76e92f4 commit c46636c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion flow/e2e/bigquery/peer_flow_bq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"
"time"

"github.com/PeerDB-io/peer-flow/connectors/utils"
"github.com/PeerDB-io/peer-flow/e2e"
"github.com/PeerDB-io/peer-flow/e2eshared"
"github.com/PeerDB-io/peer-flow/generated/protos"
Expand Down Expand Up @@ -699,9 +700,10 @@ func (s PeerFlowE2ETestSuiteBQ) Test_Types_BQ() {
createMoodEnum := "CREATE TYPE mood AS ENUM ('happy', 'sad', 'angry');"
var pgErr *pgconn.PgError
_, enumErr := s.pool.Exec(context.Background(), createMoodEnum)
if errors.As(enumErr, &pgErr) && pgErr.Code != pgerrcode.DuplicateObject {
if errors.As(enumErr, &pgErr) && pgErr.Code != pgerrcode.DuplicateObject && !utils.IsUniqueError(pgErr) {
require.NoError(s.t, enumErr)
}

_, err := s.pool.Exec(context.Background(), fmt.Sprintf(`
CREATE TABLE IF NOT EXISTS %s (id serial PRIMARY KEY,c1 BIGINT,c2 BIT,c3 VARBIT,c4 BOOLEAN,
c6 BYTEA,c7 CHARACTER,c8 varchar,c9 CIDR,c11 DATE,c12 FLOAT,c13 DOUBLE PRECISION,
Expand Down
3 changes: 2 additions & 1 deletion flow/e2e/postgres/peer_flow_pg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"sync"

"github.com/PeerDB-io/peer-flow/connectors/utils"
"github.com/PeerDB-io/peer-flow/e2e"
"github.com/PeerDB-io/peer-flow/generated/protos"
"github.com/PeerDB-io/peer-flow/model/qvalue"
Expand Down Expand Up @@ -114,7 +115,7 @@ func (s PeerFlowE2ETestSuitePG) Test_Enums_PG() {
createMoodEnum := "CREATE TYPE mood AS ENUM ('happy', 'sad', 'angry');"
var pgErr *pgconn.PgError
_, enumErr := s.pool.Exec(context.Background(), createMoodEnum)
if errors.As(enumErr, &pgErr) && pgErr.Code != pgerrcode.DuplicateObject {
if errors.As(enumErr, &pgErr) && pgErr.Code != pgerrcode.DuplicateObject && !utils.IsUniqueError(enumErr) {
require.NoError(s.t, enumErr)
}
_, err := s.pool.Exec(context.Background(), fmt.Sprintf(`
Expand Down
3 changes: 2 additions & 1 deletion flow/e2e/snowflake/peer_flow_sf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

connsnowflake "github.com/PeerDB-io/peer-flow/connectors/snowflake"
"github.com/PeerDB-io/peer-flow/connectors/utils"
"github.com/PeerDB-io/peer-flow/e2e"
"github.com/PeerDB-io/peer-flow/e2eshared"
"github.com/PeerDB-io/peer-flow/generated/protos"
Expand Down Expand Up @@ -684,7 +685,7 @@ func (s PeerFlowE2ETestSuiteSF) Test_Types_SF() {
createMoodEnum := "CREATE TYPE mood AS ENUM ('happy', 'sad', 'angry');"
var pgErr *pgconn.PgError
_, enumErr := s.pool.Exec(context.Background(), createMoodEnum)
if errors.As(enumErr, &pgErr) && pgErr.Code != pgerrcode.DuplicateObject {
if errors.As(enumErr, &pgErr) && pgErr.Code != pgerrcode.DuplicateObject && !utils.IsUniqueError(pgErr) {
require.NoError(s.t, enumErr)
}
_, err := s.pool.Exec(context.Background(), fmt.Sprintf(`
Expand Down
3 changes: 2 additions & 1 deletion flow/e2e/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/PeerDB-io/peer-flow/activities"
connpostgres "github.com/PeerDB-io/peer-flow/connectors/postgres"
connsnowflake "github.com/PeerDB-io/peer-flow/connectors/snowflake"
conn_utils "github.com/PeerDB-io/peer-flow/connectors/utils"
utils "github.com/PeerDB-io/peer-flow/connectors/utils/catalog"
"github.com/PeerDB-io/peer-flow/e2eshared"
"github.com/PeerDB-io/peer-flow/generated/protos"
Expand Down Expand Up @@ -237,7 +238,7 @@ func CreateTableForQRep(pool *pgxpool.Pool, suffix string, tableName string) err
tblFieldStr := strings.Join(tblFields, ",")
var pgErr *pgconn.PgError
_, enumErr := pool.Exec(context.Background(), createMoodEnum)
if errors.As(enumErr, &pgErr) && pgErr.Code != pgerrcode.DuplicateObject {
if errors.As(enumErr, &pgErr) && pgErr.Code != pgerrcode.DuplicateObject && !conn_utils.IsUniqueError(pgErr) {
return enumErr
}
_, err := pool.Exec(context.Background(), fmt.Sprintf(`
Expand Down

0 comments on commit c46636c

Please sign in to comment.