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 broker for test databases#19791

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

Closed
spikecurtis wants to merge1 commit intomainfromspike/internal-927-dbtestbroker
Closed
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
10 changes: 10 additions & 0 deletionsMakefile
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -636,6 +636,7 @@ GEN_FILES := \
provisionersdk/proto/provisioner.pb.go \
provisionerd/proto/provisionerd.pb.go \
vpn/vpn.pb.go \
coderd/database/dbtestutil/broker/broker.pb.go \
$(DB_GEN_FILES) \
$(SITE_GEN_FILES) \
coderd/rbac/object_gen.go \
Expand DownExpand Up@@ -683,6 +684,7 @@ gen/mark-fresh:
provisionersdk/proto/provisioner.pb.go \
provisionerd/proto/provisionerd.pb.go \
vpn/vpn.pb.go \
coderd/database/dbtestutil/broker/broker.pb.go \
coderd/database/dump.sql \
$(DB_GEN_FILES) \
site/src/api/typesGenerated.ts \
Expand DownExpand Up@@ -801,6 +803,14 @@ vpn/vpn.pb.go: vpn/vpn.proto
--go_opt=paths=source_relative \
./vpn/vpn.proto

coderd/database/dbtestutil/broker/broker.pb.go: coderd/database/dbtestutil/broker/broker.proto
protoc \
--go_out=. \
--go_opt=paths=source_relative \
--go-drpc_out=. \
--go-drpc_opt=paths=source_relative \
./coderd/database/dbtestutil/broker/broker.proto

site/src/api/typesGenerated.ts: site/node_modules/.installed $(wildcard scripts/apitypings/*) $(shell find ./codersdk $(FIND_EXCLUSIONS) -type f -name '*.go')
# -C sets the directory for the go run command
go run -C ./scripts/apitypings main.go > $@
Expand Down
36 changes: 36 additions & 0 deletionscmd/dbtestbroker/main.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
package main

// dbtestbroker is a subprocess used when testing with dbtestutil. It handles cloning Postgres databases for tests and
// is a separate process so that if the main test process dies (panics, times out, or is killed), we still clean up
// the test databases and don't leave them in Postgres.

import (
"context"
"fmt"
"io"
"os"
"os/signal"
"time"

_ "github.com/lib/pq"
"golang.org/x/xerrors"

"github.com/coder/coder/v2/coderd/database/dbtestutil/broker"
)

func main() {
connectCtx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
server, err := broker.NewService(connectCtx, os.Stdin, os.Stdout)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "\nDBTESTBROKER: %s\n", err.Error())
// nolint: gocritic
os.Exit(1)
}
signalCtx, signalCancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer signalCancel()
err = server.Serve(signalCtx)
if err != nil && !xerrors.Is(err, context.Canceled) && !xerrors.Is(err, io.EOF) {
_, _ = fmt.Fprintf(os.Stderr, "\nDBTESTBROKER: %s\n", err.Error())
}
}
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp