Skip to content

Commit

Permalink
Added assertion to check for enter action sent for internal members
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Nov 21, 2023
1 parent 6443077 commit f0e50d0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
13 changes: 13 additions & 0 deletions ably/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,19 @@ func (c *Connection) PendingItems() int {
return len(c.pending.queue)
}

type MsgWithAckCallback = msgWithAckCallback

// AckAll empties queue and acks all pending callbacks
func (c *Connection) AckAll() {
c.mtx.Lock()
cx := c.pending.Dismiss()
c.mtx.Unlock()
c.log().Debugf("resending %d messages waiting for ACK/NACK", len(cx))
for _, v := range cx {
v.onAck(nil)
}
}

func (c *Connection) SetKey(key string) {
c.mtx.Lock()
defer c.mtx.Unlock()
Expand Down
21 changes: 17 additions & 4 deletions ably/proto_presence_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,7 @@ func Test_internal_presencemap_RTP17(t *testing.T) {
})

t.Run("RTP17f, RTP17g, RTP17e: automatic re-entry whenever channel moves into ATTACHED state", func(t *testing.T) {
in, _, client, channel, stateChanges, presenceMsgCh := setup(t)
in, out, client, channel, stateChanges, presenceMsgCh := setup(t)

presenceMsg1 := &ably.PresenceMessage{
Action: ably.PresenceActionPresent,
Expand Down Expand Up @@ -1229,8 +1229,21 @@ func Test_internal_presencemap_RTP17(t *testing.T) {
var chanChange ably.ChannelStateChange
ablytest.Instantly.Recv(t, &chanChange, stateChanges, t.Fatalf)

// Enter from internal map
// ablytest.Soon.Recv(t, nil, out, t.Fatalf)
// ablytest.Soon.Recv(t, nil, out, t.Fatalf)
// Send enter for internal messages
var protoMsg *ably.ProtocolMessage
ablytest.Instantly.Recv(t, &protoMsg, out, t.Fatalf)
for _, v := range protoMsg.Presence {
assert.Equal(t, ably.PresenceActionEnter, v.Action)
assert.Equal(t, client.Connection.ID(), v.ConnectionID)
}
client.Connection.AckAll()

ablytest.Instantly.Recv(t, &protoMsg, out, t.Fatalf)
for _, v := range protoMsg.Presence {
assert.Equal(t, ably.PresenceActionEnter, v.Action)
assert.Equal(t, client.Connection.ID(), v.ConnectionID)
}
client.Connection.AckAll()
ablytest.Instantly.NoRecv(t, nil, out, t.Fatalf)
})
}
4 changes: 2 additions & 2 deletions ably/realtime_channel_spec_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ func TestRealtimeChannel_RTL4_Attach(t *testing.T) {
err = channel.Attach(ctx)

// Check that the attach message isn't sent
checkIfAttachSent := recorder.CheckIfSent(ably.ActionAttach, 1)
attachSent := ablytest.Instantly.IsTrue(checkIfAttachSent)
checkIfAttachSentFn := recorder.CheckIfSent(ably.ActionAttach, 1)
attachSent := ablytest.Instantly.IsTrue(checkIfAttachSentFn)
assert.False(t, attachSent,
"Attach message was sent before connection is established")

Expand Down

0 comments on commit f0e50d0

Please sign in to comment.