From 23a46f5e7315e63e976bbc906c73d196d8e356d3 Mon Sep 17 00:00:00 2001 From: Anthony RAYMOND Date: Thu, 7 Jan 2021 16:29:19 +0100 Subject: [PATCH] Add test case --- server/server_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/server/server_test.go b/server/server_test.go index 903e05f..010a809 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -5,6 +5,7 @@ import ( "net" "runtime" "testing" + "time" "github.com/go-stomp/stomp" . "gopkg.in/check.v1" @@ -45,6 +46,37 @@ func (s *ServerSuite) TestConnectAndDisconnect(c *C) { conn.Close() } + +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) + c.Assert(err, IsNil) + defer func() { l.Close() }() + serv := Server{ + Addr: "", + Authenticator: nil, + QueueStorage: nil, + HeartBeat: 5 * time.Millisecond, + } + go serv.Serve(l) + + conn, err := net.Dial("tcp", "127.0.0.1"+addr) + c.Assert(err, IsNil) + defer conn.Close() + + 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 + + // Ensure the server has not closed his readChannel + err = client.Send("/topic/whatever", "text/plain", []byte("hello")) + c.Assert(err, IsNil) +} + func (s *ServerSuite) TestSendToQueuesAndTopics(c *C) { ch := make(chan bool, 2) println("number cpus:", runtime.NumCPU())