Skip to content

Commit

Permalink
Add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyraymond committed Jan 7, 2021
1 parent 69b583e commit 23a46f5
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net"
"runtime"
"testing"
"time"

"github.com/go-stomp/stomp"
. "gopkg.in/check.v1"
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 23a46f5

Please sign in to comment.