Skip to content

Commit

Permalink
Improve test reliability
Browse files Browse the repository at this point in the history
  • Loading branch information
enocom committed Nov 22, 2023
1 parent 0d23018 commit b61ca0c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cmd/wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
package cmd

import (
"io"
"net"
"testing"
"time"
)

func TestWaitCommandFlags(t *testing.T) {
Expand All @@ -35,6 +37,11 @@ func TestWaitCommandFlags(t *testing.T) {
return
}
defer conn.Close()
// Use a read deadline to produce read error
conn.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
// Read client request first.
io.ReadAll(conn)
// Write a generic 200 response back.
conn.Write([]byte("HTTP/1.1 200 OK\r\n\r\n"))
}()

Expand All @@ -53,7 +60,7 @@ func TestWaitCommandFails(t *testing.T) {
_, err := invokeProxyCommand([]string{
"wait",
// assuming default host and port
"--max=500ms",
"--max=100ms",
})
if err == nil {
t.Fatal("wait should fail when endpoint does not respond")
Expand Down

0 comments on commit b61ca0c

Please sign in to comment.