Skip to content

Commit

Permalink
Added unit tests for recveing receipt timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Ridgway committed Dec 11, 2020
1 parent a75f768 commit 29df28d
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,3 +648,76 @@ func createHeartBeatConnection(
conn: fc2,
}
}

// Testing Timeouts when receiving receipts
func sendFrameHelper(f *frame.Frame, c chan *frame.Frame) {
c <- f
}

//// GIVEN_TheTimeoutIsExceededBeforeTheReceiptIsReceived_WHEN_CallingReadReceiptWithTimeout_THEN_ReturnAnError
func (s *StompSuite) Test_TimeoutTriggers(c *C) {
const timeout = 1 * time.Millisecond
f := frame.Frame{}
request := writeRequest{
Frame: &f,
C: make(chan *frame.Frame),
}

err := readReceiptWithTimeout(request, timeout)

c.Assert(err, NotNil)
}

//// GIVEN_TheChannelReceivesTheReceiptBeforeTheTimeoutExpires_WHEN_CallingReadReceiptWithTimeout_THEN_DoNotReturnAnError
func (s *StompSuite) Test_ChannelReceviesReceipt(c *C) {
const timeout = 1 * time.Second
f := frame.Frame{}
request := writeRequest{
Frame: &f,
C: make(chan *frame.Frame),
}
receipt := frame.Frame{
Command: frame.RECEIPT,
}

go sendFrameHelper(&receipt, request.C)
err := readReceiptWithTimeout(request, timeout)

c.Assert(err, IsNil)
}

//// GIVEN_TheChannelReceivesMessage_AND_TheMessageIsNotAReceipt_WHEN_CallingReadReceiptWithTimeout_THEN_ReturnAnError
func (s *StompSuite) Test_ChannelReceviesNonReceipt(c *C) {
const timeout = 1 * time.Second
f := frame.Frame{}
request := writeRequest{
Frame: &f,
C: make(chan *frame.Frame),
}
receipt := frame.Frame{
Command: "NOT A RECEIPT",
}

go sendFrameHelper(&receipt, request.C)
err := readReceiptWithTimeout(request, timeout)

c.Assert(err, NotNil)
}

//// GIVEN_TheTimeoutIsSetToZero_AND_TheMessageIsReceived_WHEN_CallingReadReceiptWithTimeout_THEN_DoNotReturnAnError
func (s *StompSuite) Test_ZeroTimeout(c *C) {
const timeout = 0 * time.Second
f := frame.Frame{}
request := writeRequest{
Frame: &f,
C: make(chan *frame.Frame),
}
receipt := frame.Frame{
Command: frame.RECEIPT,
}

go sendFrameHelper(&receipt, request.C)
err := readReceiptWithTimeout(request, timeout)

c.Assert(err, IsNil)
}

0 comments on commit 29df28d

Please sign in to comment.