Skip to content

Commit

Permalink
fix: remove flakyness in server test
Browse files Browse the repository at this point in the history
  • Loading branch information
worg committed Mar 23, 2022
1 parent aae3b21 commit 0162d4a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,28 @@ func (s *ServerSuite) TestConnectAndDisconnect(c *C) {
func (s *ServerSuite) TestHeartBeatingTolerance(c *C) {
// Heart beat should not close connection exactly after not receiving message after cx
// it should add a pretty decent amount of time to counter network delay of other timing issues
addr := ":59092"
l, err := net.Listen("tcp", addr)
l, err := net.Listen("tcp", `127.0.0.1:0`)
c.Assert(err, IsNil)
defer func() { l.Close() }()
serv := Server{
Addr: "",
Addr: l.Addr().String(),
Authenticator: nil,
QueueStorage: nil,
HeartBeat: 5 * time.Millisecond,
}
go serv.Serve(l)

conn, err := net.Dial("tcp", "127.0.0.1"+addr)
conn, err := net.Dial("tcp", l.Addr().String())
c.Assert(err, IsNil)
defer conn.Close()

client, err := stomp.Connect(conn, stomp.ConnOpt.HeartBeat(5 * time.Millisecond, 5 * time.Millisecond))
client, err := stomp.Connect(conn,
stomp.ConnOpt.HeartBeat(5 * time.Millisecond, 5 * time.Millisecond),
)
c.Assert(err, IsNil)
defer client.Disconnect()

time.Sleep(serv.HeartBeat * 50) // let it go for some time to allow client and server to exchange some heart beat
time.Sleep(serv.HeartBeat * 20) // let it go for some time to allow client and server to exchange some heart beat

// Ensure the server has not closed his readChannel
err = client.Send("/topic/whatever", "text/plain", []byte("hello"))
Expand Down

0 comments on commit 0162d4a

Please sign in to comment.