Skip to content

Commit

Permalink
Merge pull request #1750 from josephschorr/postgres-flake-fixes
Browse files Browse the repository at this point in the history
Further fixes to flaky Postgres tests
  • Loading branch information
josephschorr authored Feb 20, 2024
2 parents 58fef87 + 8dccc2a commit 3557285
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions internal/testserver/datastore/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
POSTGRES_TEST_USER = "postgres"
POSTGRES_TEST_PASSWORD = "secret"
POSTGRES_TEST_PORT = "5432"
POSTGRES_TEST_MAX_CONNECTIONS = "500"
POSTGRES_TEST_MAX_CONNECTIONS = "2000"
PGBOUNCER_TEST_PORT = "6432"
)

Expand Down Expand Up @@ -134,14 +134,14 @@ const (
)

func (b *postgresTester) NewDatastore(t testing.TB, initFunc InitFunc) datastore.Datastore {
connectStr := b.NewDatabase(t)

var migrationDriver *pgmigrations.AlembicPostgresDriver
for i := 0; i < retryCount; i++ {
md, err := pgmigrations.NewAlembicPostgresDriver(context.Background(), connectStr)
connectStr := b.NewDatabase(t)

migrationDriver, err := pgmigrations.NewAlembicPostgresDriver(context.Background(), connectStr)
if err == nil {
migrationDriver = md
break
ctx := context.WithValue(context.Background(), migrate.BackfillBatchSize, uint64(1000))
require.NoError(t, pgmigrations.DatabaseMigrations.Run(ctx, migrationDriver, b.targetMigration, migrate.LiveRun))
return initFunc("postgres", connectStr)
}

if i == retryCount-1 {
Expand All @@ -151,12 +151,8 @@ func (b *postgresTester) NewDatastore(t testing.TB, initFunc InitFunc) datastore
time.Sleep(timeBetweenRetries)
}

require.NotNil(t, migrationDriver, "failed to create migration driver")

ctx := context.WithValue(context.Background(), migrate.BackfillBatchSize, uint64(1000))
require.NoError(t, pgmigrations.DatabaseMigrations.Run(ctx, migrationDriver, b.targetMigration, migrate.LiveRun))

return initFunc("postgres", connectStr)
require.Fail(t, "failed to create datastore for testing")
return nil
}

func createNetworkBridge(t testing.TB, pool *dockertest.Pool) string {
Expand Down

0 comments on commit 3557285

Please sign in to comment.