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

Commit89fca3f

Browse files
committed
chore: add broker for test databases
1 parent4cd0ada commit89fca3f

File tree

7 files changed

+1282
-0
lines changed

7 files changed

+1282
-0
lines changed

‎Makefile‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ GEN_FILES := \
636636
provisionersdk/proto/provisioner.pb.go\
637637
provisionerd/proto/provisionerd.pb.go\
638638
vpn/vpn.pb.go\
639+
coderd/database/dbtestutil/broker/broker.pb.go\
639640
$(DB_GEN_FILES)\
640641
$(SITE_GEN_FILES)\
641642
coderd/rbac/object_gen.go\
@@ -683,6 +684,7 @@ gen/mark-fresh:
683684
provisionersdk/proto/provisioner.pb.go\
684685
provisionerd/proto/provisionerd.pb.go\
685686
vpn/vpn.pb.go\
687+
coderd/database/dbtestutil/broker/broker.pb.go\
686688
coderd/database/dump.sql\
687689
$(DB_GEN_FILES)\
688690
site/src/api/typesGenerated.ts\
@@ -801,6 +803,14 @@ vpn/vpn.pb.go: vpn/vpn.proto
801803
--go_opt=paths=source_relative\
802804
./vpn/vpn.proto
803805

806+
coderd/database/dbtestutil/broker/broker.pb.go: coderd/database/dbtestutil/broker/broker.proto
807+
protoc\
808+
--go_out=.\
809+
--go_opt=paths=source_relative\
810+
--go-drpc_out=.\
811+
--go-drpc_opt=paths=source_relative\
812+
./coderd/database/dbtestutil/broker/broker.proto
813+
804814
site/src/api/typesGenerated.ts: site/node_modules/.installed$(wildcard scripts/apitypings/*)$(shell find ./codersdk$(FIND_EXCLUSIONS) -type f -name '*.go')
805815
# -C sets the directory for the go run command
806816
go run -C ./scripts/apitypings main.go>$@

‎cmd/dbtestbroker/main.go‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package main
2+
3+
// dbtestbroker is a subprocess used when testing with dbtestutil. It handles cloning Postgres databases for tests and
4+
// is a separate process so that if the main test process dies (panics, times out, or is killed), we still clean up
5+
// the test databases and don't leave them in Postgres.
6+
7+
import (
8+
"context"
9+
"fmt"
10+
"io"
11+
"os"
12+
"os/signal"
13+
"time"
14+
15+
"golang.org/x/xerrors"
16+
17+
"github.com/coder/coder/v2/coderd/database/dbtestutil/broker"
18+
)
19+
20+
funcmain() {
21+
connectCtx,cancel:=context.WithTimeout(context.Background(),20*time.Second)
22+
defercancel()
23+
server,err:=broker.NewService(connectCtx,os.Stdin,os.Stdout)
24+
iferr!=nil {
25+
_,_=fmt.Fprintf(os.Stderr,"\nDBTESTBROKER: %s\n",err.Error())
26+
os.Exit(1)
27+
}
28+
signalCtx,signalCancel:=signal.NotifyContext(context.Background(),os.Interrupt)
29+
defersignalCancel()
30+
err=server.Serve(signalCtx)
31+
iferr!=nil&&!xerrors.Is(err,context.Canceled)&&!xerrors.Is(err,io.EOF) {
32+
_,_=fmt.Fprintf(os.Stderr,"\nDBTESTBROKER: %s\n",err.Error())
33+
}
34+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp