@@ -3,38 +3,12 @@ package handler
33import (
44 "net/http"
55 "net/http/httptest"
6- "net/url"
7- "runtime"
86 "testing"
9- "time"
107
11- "github.com/gorilla/websocket"
128 "github.com/m-lab/locate/clientgeo"
139 prom "github.com/prometheus/client_golang/api/prometheus/v1"
1410)
1511
16- func init () {
17- readDeadline = 50 * time .Millisecond
18- }
19-
20- func mustSetupTest (t testing.TB ) (* Client , * websocket.Conn , func (tb testing.TB )) {
21- c := fakeClient ()
22- s := httptest .NewServer (http .HandlerFunc (c .Heartbeat ))
23- u , _ := url .Parse (s .URL )
24- u .Scheme = "ws"
25- dialer := websocket.Dialer {}
26- ws , _ , err := dialer .Dial (u .String (), http.Header {})
27- if err != nil {
28- s .Close ()
29- t .Fatalf ("failed to establish a connection, err: %v" , err )
30- }
31-
32- return c , ws , func (t testing.TB ) {
33- s .Close ()
34- ws .Close ()
35- }
36- }
37-
3812func TestClient_Heartbeat_Error (t * testing.T ) {
3913 rw := httptest .NewRecorder ()
4014 // The header from this request will not contain the
@@ -48,21 +22,6 @@ func TestClient_Heartbeat_Error(t *testing.T) {
4822 }
4923}
5024
51- func TestClient_Heartbeat_Timeout (t * testing.T ) {
52- _ , _ , teardown := mustSetupTest (t )
53- defer teardown (t )
54-
55- // The read loop runs in a separate goroutine, so we wait for it to exit.
56- // It will exit if there are no new messages within the read deadline.
57- before := runtime .NumGoroutine ()
58- timer := time .NewTimer (2 * readDeadline )
59- <- timer .C
60- after := runtime .NumGoroutine ()
61- if after >= before {
62- t .Errorf ("Heartbeat() goroutine did not exit; got: %d, want: <%d" , after , before )
63- }
64- }
65-
6625func fakeClient () * Client {
6726 return NewClient ("mlab-sandbox" , & fakeSigner {}, & fakeLocator {}, & fakeLocatorV2 {},
6827 clientgeo .NewAppEngineLocator (), prom .NewAPI (nil ))
0 commit comments