Skip to content

chore: improve postgres test time by removing cleanup #7522

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

Merged
merged 1 commit into from
May 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,8 @@ test-postgres: test-clean test-postgres-docker
--jsonfile="gotests.json" \
--packages="./..." -- \
-covermode=atomic -coverprofile="gotests.coverage" -timeout=20m \
-parallel=4 \
-coverpkg=./... \
-count=1 -race -failfast
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove? I think it forces go test to not skip cached tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go test caching is pretty effective in reducing only duplicates, we use it for the other jobs

-race -failfast
.PHONY: test-postgres

test-postgres-docker:
Expand All @@ -627,6 +626,8 @@ test-postgres-docker:
--detach \
postgres:13 \
-c shared_buffers=1GB \
-c work_mem=1GB \
-c effective_cache_size=1GB \
-c max_connections=1000 \
-c fsync=off \
-c synchronous_commit=off \
Expand Down
11 changes: 4 additions & 7 deletions coderd/database/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,10 @@ func Open() (string, func(), error) {
return "", nil, xerrors.Errorf("create db with template: %w", err)
}

deleteDB := func() {
ddb, _ := sql.Open("postgres", dbURL)
defer ddb.Close()
_, _ = ddb.Exec("DROP DATABASE " + dbName)
}

return "postgres://postgres:postgres@127.0.0.1:5432/" + dbName + "?sslmode=disable", deleteDB, nil
return "postgres://postgres:postgres@127.0.0.1:5432/" + dbName + "?sslmode=disable", func() {
// We don't need to clean anything up here... it's just a database in a container,
// so cleaning up the container will clean up the database.
}, nil
Comment on lines +49 to +52
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this func only used in ci? would be nice if this only applied in ci so we don't disable cleanup in dogfood.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, it's used outside too. We just don't need to clean this because it isn't actual waste

}

pool, err := dockertest.NewPool("")
Expand Down