55 "errors"
66 "fmt"
77 "net/http"
8+ "net/http/httptest"
89 "sync"
910 "testing"
1011 "time"
@@ -20,6 +21,9 @@ func (tr *testReporter) Errorf(format string, args ...interface{}) {
2021 tr .msg = fmt .Sprintf (format , args ... )
2122}
2223
24+ // Client for the TestServer
25+ var testServer * httptest.Server
26+
2327func TestCheck (t * testing.T ) {
2428 leakyFuncs := []struct {
2529 f func ()
@@ -81,7 +85,7 @@ func TestCheck(t *testing.T) {
8185 DisableKeepAlives : true ,
8286 }
8387 client := & http.Client {Transport : tr }
84- _ , err := client .Get ("http://localhost:8091" )
88+ _ , err := client .Get (testServer . URL )
8589 if err != nil {
8690 t .Error (err )
8791 }
@@ -95,7 +99,7 @@ func TestCheck(t *testing.T) {
9599 DisableKeepAlives : false ,
96100 }
97101 client := & http.Client {Transport : tr }
98- _ , err := client .Get ("http://localhost:8091" )
102+ _ , err := client .Get (testServer . URL )
99103 if err != nil {
100104 t .Error (err )
101105 }
@@ -106,7 +110,7 @@ func TestCheck(t *testing.T) {
106110 // Start our keep alive server for keep alive tests
107111 ctx , cancel := context .WithCancel (context .Background ())
108112 defer cancel ()
109- go startKeepAliveEnabledServer (ctx )
113+ testServer = startKeepAliveEnabledServer (ctx )
110114
111115 // this works because the running goroutine is left running at the
112116 // start of the next test case - so the previous leaks don't affect the
@@ -134,7 +138,7 @@ func TestCheck(t *testing.T) {
134138// be based on time after the test finishes rather than time after the test's
135139// start.
136140func TestSlowTest (t * testing.T ) {
137- defer CheckTimeout (t , 1000 * time .Millisecond )()
141+ defer CheckTimeout (t , 1000 * time .Millisecond )()
138142
139143 go time .Sleep (1500 * time .Millisecond )
140144 time .Sleep (750 * time .Millisecond )
0 commit comments