Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: add postgres template caching for tests#15336

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
hugodutka merged 10 commits intomainfromhugodutka/15109-postgres-utilities
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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
2 changes: 1 addition & 1 deletionMakefile
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -765,7 +765,7 @@ sqlc-vet: test-postgres-docker
test-postgres: test-postgres-docker
# The postgres test is prone to failure, so we limit parallelism for
# more consistent execution.
$(GIT_FLAGS) DB=ciDB_FROM=$(shell go run scripts/migrate-ci/main.go)gotestsum \
$(GIT_FLAGS) DB=ci gotestsum \
--junitfile="gotests.xml" \
--jsonfile="gotests.json" \
--packages="./..." -- \
Expand Down
3 changes: 1 addition & 2 deletionscli/resetpassword_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,9 +32,8 @@ func TestResetPassword(t *testing.T) {
const newPassword = "MyNewPassword!"

// start postgres and coder server processes
connectionURL,closeFunc,err := dbtestutil.Open()
connectionURL, err := dbtestutil.Open(t)
require.NoError(t, err)
defer closeFunc()
ctx, cancelFunc := context.WithCancel(context.Background())
serverDone := make(chan struct{})
serverinv, cfg := clitest.New(t,
Expand Down
12 changes: 4 additions & 8 deletionscli/server_createadminuser_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -85,9 +85,8 @@ func TestServerCreateAdminUser(t *testing.T) {
// Skip on non-Linux because it spawns a PostgreSQL instance.
t.SkipNow()
}
connectionURL,closeFunc,err := dbtestutil.Open()
connectionURL, err := dbtestutil.Open(t)
require.NoError(t, err)
defer closeFunc()

sqlDB, err := sql.Open("postgres", connectionURL)
require.NoError(t, err)
Expand DownExpand Up@@ -151,9 +150,8 @@ func TestServerCreateAdminUser(t *testing.T) {
// Skip on non-Linux because it spawns a PostgreSQL instance.
t.SkipNow()
}
connectionURL,closeFunc,err := dbtestutil.Open()
connectionURL, err := dbtestutil.Open(t)
require.NoError(t, err)
defer closeFunc()

ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
defer cancel()
Expand DownExpand Up@@ -185,9 +183,8 @@ func TestServerCreateAdminUser(t *testing.T) {
// Skip on non-Linux because it spawns a PostgreSQL instance.
t.SkipNow()
}
connectionURL,closeFunc,err := dbtestutil.Open()
connectionURL, err := dbtestutil.Open(t)
require.NoError(t, err)
defer closeFunc()

ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
defer cancel()
Expand DownExpand Up@@ -225,9 +222,8 @@ func TestServerCreateAdminUser(t *testing.T) {
// Skip on non-Linux because it spawns a PostgreSQL instance.
t.SkipNow()
}
connectionURL,closeFunc,err := dbtestutil.Open()
connectionURL, err := dbtestutil.Open(t)
require.NoError(t, err)
defer closeFunc()
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()

Expand Down
6 changes: 2 additions & 4 deletionscli/server_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1598,9 +1598,8 @@ func TestServer_Production(t *testing.T) {
// Skip on non-Linux because it spawns a PostgreSQL instance.
t.SkipNow()
}
connectionURL,closeFunc,err := dbtestutil.Open()
connectionURL, err := dbtestutil.Open(t)
require.NoError(t, err)
defer closeFunc()

// Postgres + race detector + CI = slow.
ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitSuperLong*3)
Expand DownExpand Up@@ -1803,9 +1802,8 @@ func TestConnectToPostgres(t *testing.T) {

log := slogtest.Make(t, nil)

dbURL,closeFunc,err := dbtestutil.Open()
dbURL, err := dbtestutil.Open(t)
require.NoError(t, err)
t.Cleanup(closeFunc)

sqlDB, err := cli.ConnectToPostgres(ctx, log, "postgres", dbURL)
require.NoError(t, err)
Expand Down
3 changes: 1 addition & 2 deletionscoderd/database/db_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -87,9 +87,8 @@ func TestNestedInTx(t *testing.T) {
func testSQLDB(t testing.TB) *sql.DB {
t.Helper()

connection,closeFn,err := dbtestutil.Open()
connection, err := dbtestutil.Open(t)
require.NoError(t, err)
t.Cleanup(closeFn)

db, err := sql.Open("postgres", connection)
require.NoError(t, err)
Expand Down
15 changes: 7 additions & 8 deletionscoderd/database/dbtestutil/db.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -95,21 +95,17 @@ func NewDB(t testing.TB, opts ...Option) (database.Store, pubsub.Pubsub) {
opt(&o)
}

db:= dbmem.New()
ps:=pubsub.NewInMemory()
vardbdatabase.Store
varps pubsub.Pubsub
if WillUsePostgres() {
connectionURL := os.Getenv("CODER_PG_CONNECTION_URL")
if connectionURL == "" && o.url != "" {
connectionURL = o.url
}
if connectionURL == "" {
var (
err error
closePg func()
)
connectionURL, closePg, err = Open()
var err error
connectionURL, err = Open(t)
require.NoError(t, err)
t.Cleanup(closePg)
}

if o.fixedTimezone == "" {
Expand DownExpand Up@@ -142,6 +138,9 @@ func NewDB(t testing.TB, opts ...Option) (database.Store, pubsub.Pubsub) {
t.Cleanup(func() {
_ = ps.Close()
})
} else {
db = dbmem.New()
ps = pubsub.NewInMemory()
}

return db, ps
Expand Down
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp