diff --git a/devtools/cmd/wait_available/main.go b/devtools/cmd/wait_available/main.go index 31fa72e09..e067f5bdb 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 c6bb71314..52a029f07 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 diff --git a/tests/screentest/run.sh b/tests/screentest/run.sh index 3edb33dac..c3a1a5297 100755 --- a/tests/screentest/run.sh +++ b/tests/screentest/run.sh @@ -131,9 +131,8 @@ main() { dcompose up --detach chromedp dcompose up --detach --force-recreate frontend dcompose run --rm --entrypoint bash go -c " - export WAITFORIT_TIMEOUT=120 go install golang.org/x/website/cmd/screentest@latest - go run ./devtools/cmd/wait_available frontend:8080 -- + go run ./devtools/cmd/wait_available --timeout 120s frontend:8080 -- $(echo $cmd)" elif [ "$env" = local ]; then if ! nc -z localhost 9222; then