Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Commit

Permalink
Fixes race condition in loggregatorlib handlers test suite
Browse files Browse the repository at this point in the history
- Checks that the handlerDone chan is closed after every test before moving on.

[#118980919]
  • Loading branch information
wfernandes committed May 5, 2016
1 parent 3cc83ba commit 03bfd6e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions server/handlers/websocket_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ var _ = Describe("WebsocketHandler", func() {
}
go ws.ReadMessage()
close(messagesChan)
Eventually(handlerDone).Should(BeClosed())
})

It("should err when websocket upgrade fails", func() {
resp, err := http.Get(testServer.URL)
Expect(err).NotTo(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusBadRequest))
Eventually(handlerDone).Should(BeClosed())

})

Expand Down Expand Up @@ -116,6 +118,7 @@ var _ = Describe("WebsocketHandler", func() {

Consistently(handlerDone, 200*time.Millisecond).ShouldNot(BeClosed())
close(messagesChan)
Eventually(handlerDone).Should(BeClosed())
})

It("should continue when the client sends old style keepalives", func() {
Expand All @@ -132,6 +135,7 @@ var _ = Describe("WebsocketHandler", func() {

Consistently(handlerDone, 200*time.Millisecond).ShouldNot(BeClosed())
close(messagesChan)
Eventually(handlerDone).Should(BeClosed())
})

It("should send a closing message", func() {
Expand All @@ -140,6 +144,7 @@ var _ = Describe("WebsocketHandler", func() {
close(messagesChan)
_, _, err = ws.ReadMessage()
Expect(err.Error()).To(ContainSubstring("websocket: close 1000"))
Eventually(handlerDone).Should(BeClosed())
})

Context("when the KeepAlive expires", func() {
Expand All @@ -152,6 +157,7 @@ var _ = Describe("WebsocketHandler", func() {
_, _, err = ws.ReadMessage()
Expect(err.Error()).To(ContainSubstring("1008"))
Expect(err.Error()).To(ContainSubstring("Client did not respond to ping before keep-alive timeout expired."))
Eventually(handlerDone).Should(BeClosed())
})

It("logs an appropriate message", func() {
Expand All @@ -162,6 +168,7 @@ var _ = Describe("WebsocketHandler", func() {

expectedMessage := fmt.Sprintf("websocket handler: Connection from %s timed out", ws.LocalAddr().String())
Expect(loggertesthelper.TestLoggerSink.LogContents()).To(ContainSubstring(expectedMessage))
Eventually(handlerDone).Should(BeClosed())
})
})

Expand All @@ -174,6 +181,7 @@ var _ = Describe("WebsocketHandler", func() {

expectedMessage := fmt.Sprintf("websocket handler: connection from %s was closed", ws.LocalAddr().String())
Eventually(loggertesthelper.TestLoggerSink.LogContents).Should(ContainSubstring(expectedMessage))
Eventually(handlerDone).Should(BeClosed())
})
})
})
Expand Down

0 comments on commit 03bfd6e

Please sign in to comment.