diff options
| author | Michael Matloob <matloob@golang.org> | 2024-01-02 16:12:20 -0500 |
|---|---|---|
| committer | Michael Matloob <matloob@golang.org> | 2024-01-03 16:21:50 +0000 |
| commit | e232f565e9429005758ab0132fbe5347f5790dc0 (patch) | |
| tree | 3376fd0fb430f33a6573c4e8b89b34b5003462f6 /devtools | |
| parent | 475d4c57676e9e93276be3b802aaa7e758610ead (diff) | |
| download | go-x-pkgsite-e232f565e9429005758ab0132fbe5347f5790dc0.tar.xz | |
devtools/cmd/wait_available: add timeout flag
And properly set the timeout flag in devtools/docker/compose.yaml and
tests/screentest/run.sh instead of dropping it.
Change-Id: I6aeee276b5fe1d01bef2b809b017a570c4f73368
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/553535
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Michael Matloob <matloob@golang.org>
kokoro-CI: kokoro <noreply+kokoro@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dan Peterson <danp@danp.net>
Diffstat (limited to 'devtools')
| -rw-r--r-- | devtools/cmd/wait_available/main.go | 19 | ||||
| -rw-r--r-- | devtools/docker/compose.yaml | 15 |
2 files changed, 16 insertions, 18 deletions
diff --git a/devtools/cmd/wait_available/main.go b/devtools/cmd/wait_available/main.go index 31fa72e0..e067f5bd 100644 --- a/devtools/cmd/wait_available/main.go +++ b/devtools/cmd/wait_available/main.go @@ -8,6 +8,7 @@ package main import ( "context" + "flag" "net" "os" "os/exec" @@ -18,27 +19,29 @@ import ( "golang.org/x/pkgsite/internal/log" ) -var timeout = 15 * time.Second +var timeout = flag.Duration("timeout", 15*time.Second, "timeout duration") func main() { + flag.Parse() ctx := context.Background() - if len(os.Args) < 2 { + args := flag.Args() + if len(args) < 1 { log.Fatalf(ctx, "expected at least one argument; got none") } - hostport := os.Args[1] + hostport := args[0] var command []string - if len(os.Args) > 2 { - if os.Args[2] != "--" { - log.Fatalf(ctx, "expected second argument to be \"--\"; got %q", os.Args[2]) + if len(args) > 1 { + if args[1] != "--" { + log.Fatalf(ctx, "expected second argument to be \"--\"; got %q", args[1]) } - command = os.Args[3:] + command = args[2:] } start := time.Now() for { - if time.Since(start) > timeout { + if time.Since(start) > *timeout { break } if conn, err := net.DialTimeout("tcp", hostport, 1*time.Second); err != nil { diff --git a/devtools/docker/compose.yaml b/devtools/docker/compose.yaml index c6bb7131..52a029f0 100644 --- a/devtools/docker/compose.yaml +++ b/devtools/docker/compose.yaml @@ -37,8 +37,7 @@ services: GO_DISCOVERY_TESTDB: ${GO_DISCOVERY_TESTDB:-"true"} # TERM is set to xterm-256color for use by devtools/lib.sh. TERM: xterm-256color - WAITFORIT_TIMEOUT: 300 - entrypoint: go run ./devtools/cmd/wait_available db:5432 -- ./all.bash + entrypoint: go run ./devtools/cmd/wait_available --timeout 300s db:5432 -- ./all.bash volumes: - ../../:/pkgsite working_dir: /pkgsite @@ -48,8 +47,7 @@ services: - frontend environment: <<: [*database-variables, *go-variables] - WAITFORIT_TIMEOUT: 300 - entrypoint: go run ./devtools/cmd/wait_available frontend:8080 -- go run + entrypoint: go run ./devtools/cmd/wait_available --timeout 300s frontend:8080 -- go run command: "tests/search/main.go -frontend http://frontend:8080" volumes: - ../../:/pkgsite @@ -60,8 +58,7 @@ services: - frontend environment: <<: *go-variables - WAITFORIT_TIMEOUT: 300 - entrypoint: go run ./devtools/cmd/wait_available frontend:8080 -- go run + entrypoint: go run ./devtools/cmd/wait_available --timeout 300s frontend:8080 -- go run command: "tests/api/main.go -frontend http://frontend:8080 -all compare " volumes: - ../../:/pkgsite @@ -72,14 +69,13 @@ services: depends_on: - db command: bash -c " - go run ./devtools/cmd/wait_available db:5432 -- + go run ./devtools/cmd/wait_available --timeout 300s db:5432 -- go run ./devtools/cmd/db/main.go create && go run ./devtools/cmd/db/main.go migrate && go run ./cmd/frontend -host=0.0.0.0:8080" environment: <<: [*database-variables, *go-variables] PORT: 8080 - WAITFORIT_TIMEOUT: 300 volumes: - ../../:/pkgsite - gomodcache:/gomodcache @@ -94,13 +90,12 @@ services: # time seeddb runs. If this ends up being flaky, we should add a check here. command: bash -c " echo GO_DISCOVERY_CONFIG_DYNAMIC=$GO_DISCOVERY_CONFIG_DYNAMIC && - go run ./devtools/cmd/wait_available db:5432 -- + go run ./devtools/cmd/wait_available --timeout 300s db:5432 -- go run ./devtools/cmd/db/main.go create && go run ./devtools/cmd/db/main.go migrate && go run ./devtools/cmd/seeddb/main.go -seed ${GO_DISCOVERY_SEED_DB_FILE:-seed.txt}" environment: <<: [*database-variables, *go-variables] - WAITFORIT_TIMEOUT: 300 volumes: - ../../:/pkgsite - gomodcache:/gomodcache |
