diff --git a/src/autoscaler/metricsgateway/helpers/ws_helper_test.go b/src/autoscaler/metricsgateway/helpers/ws_helper_test.go index 6bb8b0c9a..9c7785f53 100644 --- a/src/autoscaler/metricsgateway/helpers/ws_helper_test.go +++ b/src/autoscaler/metricsgateway/helpers/ws_helper_test.go @@ -105,6 +105,10 @@ var _ = Describe("WsHelper", func() { err = wsHelper.SetupConn() Expect(err).NotTo(HaveOccurred()) + err = wsHelper.Ping() + Expect(err).ShouldNot(HaveOccurred()) + Eventually(pingPongChan, 5*time.Second, 1*time.Second).Should(Receive(Equal(1))) + }) It("close the websocket connection", func() { wsHelper.CloseConn() diff --git a/src/autoscaler/testhelpers/websocket_handler.go b/src/autoscaler/testhelpers/websocket_handler.go index 370e1a89e..48c2efe32 100644 --- a/src/autoscaler/testhelpers/websocket_handler.go +++ b/src/autoscaler/testhelpers/websocket_handler.go @@ -30,7 +30,10 @@ func NewWebsocketHandler(m chan []byte, pingPongChan chan int, keepAlive time.Du func (h *WebsocketHandler) CloseWSConnection() { h.conLock.Lock() defer h.conLock.Unlock() - h.wsConn.Close() + if h.wsConn != nil { + h.wsConn.Close() + + } } func (h *WebsocketHandler) ServeWebsocket(rw http.ResponseWriter, r *http.Request) { upgrader := websocket.Upgrader{