Skip to content

Commit

Permalink
Setting state to disconnected instead of connecting when DISCONNECTED…
Browse files Browse the repository at this point in the history
… msg received
  • Loading branch information
sacOO7 committed Aug 30, 2024
1 parent 83d180d commit 9bea0c0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 3 additions & 3 deletions ably/realtime_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ func (c *Connection) eventloop() {
c.mtx.Unlock()
return
}
// RTN23a
// RTN23a, RTN15a
c.lockSetState(ConnectionStateDisconnected, err, 0)
c.mtx.Unlock()
arg := connArgs{
Expand Down Expand Up @@ -871,15 +871,15 @@ func (c *Connection) eventloop() {
return
}
// RTN15h2, RTN22a
c.setState(ConnectionStateConnecting, newErrorFromProto(msg.Error), 0)
c.setState(ConnectionStateDisconnected, newErrorFromProto(msg.Error), 0)
c.reauthorize(connArgs{
lastActivityAt: lastActivityAt,
connDetails: connDetails,
})
return
}
// RTN15h3
c.setState(ConnectionStateConnecting, newErrorFromProto(msg.Error), 0)
c.setState(ConnectionStateDisconnected, newErrorFromProto(msg.Error), 0)
c.reconnect(connArgs{
lastActivityAt: lastActivityAt,
connDetails: connDetails,
Expand Down
11 changes: 8 additions & 3 deletions ably/realtime_conn_spec_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ func Test_RTN4a_ConnectionEventForStateChange(t *testing.T) {
"fake disconnection failed: %v", err)

ablytest.Soon.Recv(t, nil, changes, t.Fatalf)

})

t.Run(fmt.Sprintf("on %s", ably.ConnectionStateSuspended), func(t *testing.T) {
Expand Down Expand Up @@ -1592,6 +1591,8 @@ func TestRealtimeConn_RTN15h2_ReauthWithBadToken(t *testing.T) {
// Connecting state expected before a reauthorization and reconnection attempt.
var stateChange ably.ConnectionStateChange
ablytest.Instantly.Recv(t, &stateChange, stateChanges, t.Fatalf)
assert.Equal(t, ably.ConnectionStateDisconnected, stateChange.Current)
ablytest.Instantly.Recv(t, &stateChange, stateChanges, t.Fatalf)
assert.Equal(t, ably.ConnectionStateConnecting, stateChange.Current)

// The DISCONNECTED causes a reauth, and dial again with the new
Expand Down Expand Up @@ -1673,6 +1674,8 @@ func TestRealtimeConn_RTN15h2_Success(t *testing.T) {
// Connecting state expected before a reauthorization and reconnection attempt.
var stateChange ably.ConnectionStateChange
ablytest.Instantly.Recv(t, &stateChange, stateChanges, t.Fatalf)
assert.Equal(t, ably.ConnectionStateDisconnected, stateChange.Current)
ablytest.Instantly.Recv(t, &stateChange, stateChanges, t.Fatalf)
assert.Equal(t, ably.ConnectionStateConnecting, stateChange.Current)
assert.Equal(t, ably.ConnectionStateConnecting, c.Connection.State())

Expand Down Expand Up @@ -1749,6 +1752,8 @@ func TestRealtimeConn_RTN15h3_Success(t *testing.T) {
// Connecting state expected before reconnection attempt.
var stateChange ably.ConnectionStateChange
ablytest.Instantly.Recv(t, &stateChange, stateChanges, t.Fatalf)
assert.Equal(t, ably.ConnectionStateDisconnected, stateChange.Current)
ablytest.Instantly.Recv(t, &stateChange, stateChanges, t.Fatalf)
assert.Equal(t, ably.ConnectionStateConnecting, stateChange.Current)
assert.Equal(t, ably.ConnectionStateConnecting, c.Connection.State())

Expand All @@ -1772,7 +1777,7 @@ func TestRealtimeConn_RTN15h3_Success(t *testing.T) {
ablytest.Instantly.Recv(t, &change, stateChanges, t.Fatalf)

assert.Equal(t, ably.ConnectionEventConnected, change.Event,
"expected UPDATED event; got %v", change)
"expected CONNECTED event; got %v", change)

// Expect no further events.break
ablytest.Instantly.NoRecv(t, nil, stateChanges, t.Fatalf)
Expand Down Expand Up @@ -1805,7 +1810,7 @@ func TestRealtimeConn_RTN15h_Integration_ClientInitiatedAuth(t *testing.T) {
assert.NoError(t, err)

for i := 0; i < 3; i++ {
err = ablytest.Wait(ablytest.ConnWaiter(realtime, nil, ably.ConnectionEventConnecting), nil)
err = ablytest.Wait(ablytest.ConnWaiter(realtime, nil, ably.ConnectionEventDisconnected), nil)
var errorInfo *ably.ErrorInfo
assert.Error(t, err)
assert.ErrorAs(t, err, &errorInfo)
Expand Down

0 comments on commit 9bea0c0

Please sign in to comment.