Skip to content

Commit

Permalink
devtools/cmd/wait_available: add timeout flag
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Jonathan Amsterdam <[email protected]>
Run-TryBot: Michael Matloob <[email protected]>
kokoro-CI: kokoro <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Dan Peterson <[email protected]>
  • Loading branch information
matloob committed Jan 3, 2024
1 parent 475d4c5 commit e232f56
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
19 changes: 11 additions & 8 deletions devtools/cmd/wait_available/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package main

import (
"context"
"flag"
"net"
"os"
"os/exec"
Expand All @@ -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 {
Expand Down
15 changes: 5 additions & 10 deletions devtools/docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/screentest/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e232f56

Please sign in to comment.