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

test: change to explicitly compiling dbcleaner on posix#20206

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
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 deletioncoderd/database/dbtestutil/broker.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -150,7 +150,7 @@ func (b *Broker) init(t TBSubset) error {
b.uuid=uuid.New()
ctx,cancel:=context.WithTimeout(context.Background(),20*time.Second)
defercancel()
b.cleanerFD,err=startCleaner(ctx,b.uuid,coderTestingParams.DSN())
b.cleanerFD,err=startCleaner(ctx,t,b.uuid,coderTestingParams.DSN())
iferr!=nil {
returnxerrors.Errorf("start test db cleaner: %w",err)
}
Expand Down
5 changes: 2 additions & 3 deletionscoderd/database/dbtestutil/cleaner.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,6 @@ import (
"fmt"
"io"
"os"
"os/exec"
"os/signal"
"time"

Expand DownExpand Up@@ -39,8 +38,8 @@ func init() {

// startCleaner starts the cleaner in a subprocess. holdThis is an opaque reference that needs to be kept from being
// garbage collected until we are done with all test databases (e.g. the end of the process).
func startCleaner(ctx context.Context, parentUUID uuid.UUID, dsn string) (holdThis any, err error) {
cmd :=exec.Command("go", "run", "github.com/coder/coder/v2/coderd/database/dbtestutil/cleanercmd")
func startCleaner(ctx context.Context,t TBSubset,parentUUID uuid.UUID, dsn string) (holdThis any, err error) {
cmd :=cleanerCmd(t)
cmd.Env = append(os.Environ(),
fmt.Sprintf("%s=%s", envCleanerParentUUID, parentUUID.String()),
fmt.Sprintf("%s=%s", envCleanerDSN, dsn),
Expand Down
34 changes: 34 additions & 0 deletionscoderd/database/dbtestutil/cleaner_posix.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
//go:build !windows

package dbtestutil

import (
"os/exec"
"path/filepath"
"time"
)

const timeFormat = "2006-01-02 15:04:05.000"

// cleanerCmd builds the cleaner binary in a temporary directory and returns a command to execute it. We can do this on
// POSIX because it's OK to delete the temporary directory after the test: the binary can still run. This is not
// possible on Windows because cleaning the temporary directory will fail if the binary is still running.
// c.f. cleaner_windows.go.
func cleanerCmd(t TBSubset) *exec.Cmd {
start := time.Now()
t.Logf("[%s] starting cleaner binary build", start.Format(timeFormat))
tempDir := t.TempDir()
cleanerBinary := filepath.Join(tempDir, "cleaner")

buildCmd := exec.Command("go", "build", "-o", cleanerBinary, "github.com/coder/coder/v2/coderd/database/dbtestutil/cleanercmd")
output, err := buildCmd.CombinedOutput()
if err != nil {
t.Logf("failed to build cleaner binary: %v", err)
t.Logf("output: %s", string(output))
// Fall back to go run if build fails
return exec.Command("go", "run", "github.com/coder/coder/v2/coderd/database/dbtestutil/cleanercmd")
}
t.Logf("[%s] cleaner binary %s built in %s", time.Now().Format(timeFormat), cleanerBinary, time.Since(start))

return exec.Command(cleanerBinary)
}
11 changes: 11 additions & 0 deletionscoderd/database/dbtestutil/cleaner_windows.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
//go:build windows

package dbtestutil

import"os/exec"

// cleanerCmd returns a command to execute the cleaner binary. We do this with go run on Windows because we can't
// delete the temporary directory after the test: the binary will still be running. c.f. cleaner_posix.go.
funccleanerCmd(_TBSubset)*exec.Cmd {
returnexec.Command("go","run","github.com/coder/coder/v2/coderd/database/dbtestutil/cleanercmd")
}
1 change: 1 addition & 0 deletionscoderd/database/dbtestutil/postgres.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -166,6 +166,7 @@ type TBSubset interface {
Cleanup(func())
Helper()
Logf(formatstring,args...any)
TempDir()string
}

// Open creates a new PostgreSQL database instance.
Expand Down
4 changes: 4 additions & 0 deletionscoderd/database/gen/dump/main.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,6 +35,10 @@ func (*mockTB) Logf(format string, args ...any) {
_,_=fmt.Printf(format,args...)
}

func (*mockTB)TempDir()string {
panic("not implemented")
}

funcmain() {
t:=&mockTB{}
deferfunc() {
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp