Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*** DO NOT MERGE *** Untangle testpachd control flow #9915

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 0 additions & 26 deletions src/internal/cleanup/BUILD.bazel

This file was deleted.

56 changes: 0 additions & 56 deletions src/internal/cleanup/cleanup.go

This file was deleted.

52 changes: 0 additions & 52 deletions src/internal/cleanup/cleanup_test.go

This file was deleted.

1 change: 0 additions & 1 deletion src/internal/dockertestenv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ go_library(
visibility = ["//src:__subpackages__"],
deps = [
"//src/internal/backoff",
"//src/internal/cleanup",
"//src/internal/dbutil",
"//src/internal/errors",
"//src/internal/log",
Expand Down
88 changes: 51 additions & 37 deletions src/internal/dockertestenv/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"time"

"github.com/pachyderm/pachyderm/v2/src/internal/backoff"
"github.com/pachyderm/pachyderm/v2/src/internal/cleanup"
"github.com/pachyderm/pachyderm/v2/src/internal/dbutil"
"github.com/pachyderm/pachyderm/v2/src/internal/errors"
"github.com/pachyderm/pachyderm/v2/src/internal/log"
Expand Down Expand Up @@ -124,16 +123,39 @@ func NewTestDBConfig(t testing.TB) DBConfig {
}

// NewTestDBConfigCtx returns a DBConfig for an environment outside of tests.
func NewTestDBConfigCtx(ctx context.Context) (config DBConfig, cleaner *cleanup.Cleaner, _ error) {
func NewTestDBConfigCtx(ctx context.Context) (DBConfig, error) {
var (
dbName = testutil.GenerateEphemeralDBName()
dexName = testutil.UniqueString("dex")
config = DBConfig{
Direct: PostgresConfig{
Host: postgresHost(),
Port: postgresPort,
User: DefaultPostgresUser,
Password: DefaultPostgresPassword,
DBName: dbName,
},
PGBouncer: PostgresConfig{
Host: PGBouncerHost(),
Port: PGBouncerPort,
User: DefaultPostgresUser,
Password: DefaultPostgresPassword,
DBName: dbName,
},
Identity: PostgresConfig{
Host: PGBouncerHost(),
Port: PGBouncerPort,
User: DefaultPostgresUser,
Password: DefaultPostgresPassword,
DBName: dexName,
},
}
)
cleaner = new(cleanup.Cleaner)

if err := backoff.Retry(func() error {
return EnsureDBEnv(ctx)
}, backoff.NewConstantBackOff(time.Second*3)); err != nil {
return config, cleaner, errors.Wrap(err, "wait for database to be created")
return config, errors.Wrap(err, "wait for database to be created")
}

db, err := dbutil.NewDB(
Expand All @@ -142,45 +164,37 @@ func NewTestDBConfigCtx(ctx context.Context) (config DBConfig, cleaner *cleanup.
dbutil.WithHostPort(PGBouncerHost(), PGBouncerPort),
dbutil.WithDBName(DefaultPostgresDatabase))
if err != nil {
return config, cleaner, errors.Wrap(err, "NewDB")
return config, errors.Wrap(err, "NewDB")
}
cleaner.AddCleanup("close db connection", db.Close)
defer db.Close()

if err := testutil.CreateEphemeralDBNontest(ctx, db, dbName); err != nil {
return config, cleaner, errors.Wrapf(err, "CreateEphemeralDB(%v)", dbName)
return config, errors.Wrapf(err, "CreateEphemeralDB(%v)", dbName)
}
cleaner.AddCleanupCtx("cleanup pach database", func(ctx context.Context) error {
return errors.Wrapf(testutil.CleanupEphemeralDB(ctx, db, dbName), "cleanup database %v", dbName)
})
if err := testutil.CreateEphemeralDBNontest(ctx, db, dexName); err != nil {
return config, cleaner, errors.Wrapf(err, "CreateEphemeralDB(%v)", dexName)
return config, errors.Wrapf(err, "CreateEphemeralDB(%v)", dexName)
}
cleaner.AddCleanupCtx("cleanup dex database", func(ctx context.Context) error {
return errors.Wrapf(testutil.CleanupEphemeralDB(ctx, db, dexName), "cleanup database %v", dbName)
})
return DBConfig{
Direct: PostgresConfig{
Host: postgresHost(),
Port: postgresPort,
User: DefaultPostgresUser,
Password: DefaultPostgresPassword,
DBName: dbName,
},
PGBouncer: PostgresConfig{
Host: PGBouncerHost(),
Port: PGBouncerPort,
User: DefaultPostgresUser,
Password: DefaultPostgresPassword,
DBName: dbName,
},
Identity: PostgresConfig{
Host: PGBouncerHost(),
Port: PGBouncerPort,
User: DefaultPostgresUser,
Password: DefaultPostgresPassword,
DBName: dexName,
},
}, cleaner, nil
return config, nil
}

func (config DBConfig) Cleanup(ctx context.Context) error {
db, err := dbutil.NewDB(
dbutil.WithMaxOpenConns(1),
dbutil.WithUserPassword(DefaultPostgresUser, DefaultPostgresPassword),
dbutil.WithHostPort(PGBouncerHost(), PGBouncerPort),
dbutil.WithDBName(DefaultPostgresDatabase))
for _, c := range []PostgresConfig{config.Direct, config.Identity} {
if err != nil {
log.Error(ctx, "opening", zap.String("db", c.DBName), zap.Error(err))
continue
}
if err := testutil.CleanupEphemeralDB(ctx, db, c.DBName); err != nil {
log.Error(ctx, "deleting", zap.String("db", c.DBName), zap.Error(err))
continue
}

}
return errors.Wrap(db.Close(), "closing database")
}

// NewTestDB creates a new database connection scoped to the test.
Expand Down
1 change: 0 additions & 1 deletion src/internal/pachd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ go_library(
"//src/debug",
"//src/enterprise",
"//src/identity",
"//src/internal/cleanup",
"//src/internal/client",
"//src/internal/clusterstate",
"//src/internal/collection",
Expand Down