Skip to content

Commit 10d4873

Browse files
authored
Merge pull request kubernetes#120694 from aojea/ws_healthchec
add loging and bump timers to avoid races
2 parents 3cfdf3c + 40618b7 commit 10d4873

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

staging/src/k8s.io/client-go/tools/remotecommand/websocket_test.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636

3737
gwebsocket "github.com/gorilla/websocket"
3838

39-
"k8s.io/api/core/v1"
39+
v1 "k8s.io/api/core/v1"
4040
apierrors "k8s.io/apimachinery/pkg/api/errors"
4141
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4242
"k8s.io/apimachinery/pkg/util/httpstream/wsstream"
@@ -1054,7 +1054,13 @@ func TestWebSocketClient_HeartbeatSucceeds(t *testing.T) {
10541054
t.Fatalf("unable to upgrade to create websocket connection: %v", err)
10551055
}
10561056
defer conn.Close()
1057-
conn.ReadMessage() //nolint:errcheck
1057+
for {
1058+
_, _, err := conn.ReadMessage()
1059+
if err != nil {
1060+
t.Logf("server err reading message: %v", err)
1061+
return
1062+
}
1063+
}
10581064
}))
10591065
defer websocketServer.Close()
10601066
// Create a raw websocket client, connecting to the websocket server.
@@ -1067,8 +1073,8 @@ func TestWebSocketClient_HeartbeatSucceeds(t *testing.T) {
10671073
// Create a heartbeat using the client websocket connection, and start it.
10681074
// "period" is less than "deadline", so ping/pong heartbeat will succceed.
10691075
var expectedMsg = "test heartbeat message"
1070-
var period = 10 * time.Millisecond
1071-
var deadline = 20 * time.Millisecond
1076+
var period = 100 * time.Millisecond
1077+
var deadline = 200 * time.Millisecond
10721078
heartbeat := newHeartbeat(client, period, deadline)
10731079
heartbeat.setMessage(expectedMsg)
10741080
// Add a channel to the handler to retrieve the "pong" message.
@@ -1079,7 +1085,16 @@ func TestWebSocketClient_HeartbeatSucceeds(t *testing.T) {
10791085
return pongHandler(msg)
10801086
})
10811087
go heartbeat.start()
1082-
go client.ReadMessage() //nolint:errcheck
1088+
go func() {
1089+
for {
1090+
_, _, err := client.ReadMessage()
1091+
if err != nil {
1092+
t.Logf("client err reading message: %v", err)
1093+
return
1094+
}
1095+
}
1096+
}()
1097+
10831098
select {
10841099
case actualMsg := <-pongMsgCh:
10851100
close(heartbeat.closer)

0 commit comments

Comments
 (0)