Skip to content

Commit

Permalink
[WIP] try to fix race condition and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
norbjd committed Apr 7, 2024
1 parent 140d05f commit 00b30cd
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions test/gracefulshutdown/gracefulshutdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,23 @@ func TestGracefulShutdown(t *testing.T) {

var statusCode int

go func() {
reqURL := fmt.Sprintf("http://%s.example.com?timeout=%d", name, delay.Milliseconds())
req, err := http.NewRequest("GET", reqURL, nil)
if err != nil {
t.Fatal("Error making GET request:", err)
}
reqURL := fmt.Sprintf("http://%s.example.com?timeout=%d", name, delay.Milliseconds())
req, err := http.NewRequest("GET", reqURL, nil)
if err != nil {
t.Fatal("Error making GET request:", err)
}

errs := make(chan error, 1)

go func() {
resp, err := client.Do(req)
defer resp.Body.Close()

Check failure on line 94 in test/gracefulshutdown/gracefulshutdown_test.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

httpresponse: using resp before checking for errors (govet)

if err != nil {
t.Fatal(err)
statusCode = resp.StatusCode
}
defer resp.Body.Close()

statusCode = resp.StatusCode
errs <- err
}()

time.Sleep(2 * time.Second)
Expand All @@ -103,7 +106,10 @@ func TestGracefulShutdown(t *testing.T) {
t.Fatalf("Failed to delete pod %s: %v", gatewayPodName, err)
}

time.Sleep(delay)
err = <-errs
if err != nil {
t.Fatal(err)
}

assert.Equal(t, statusCode, http.StatusOK)
}

0 comments on commit 00b30cd

Please sign in to comment.