Skip to content

Commit

Permalink
Fix test case RealtimeClientPresenceTests.test__032__Presence__enter_…
Browse files Browse the repository at this point in the history
…_entering_without_an_explicit_PresenceMessage_clientId_should_implicitly_use_the_clientId_of_the_current_connection

This fixes the crash

> Fatal error: Index out of range: file Swift/ContiguousArrayBuffer.swift, line 444
> (…)
> (RealtimeClientPresenceTests.swift:1088)

which comes from an out of bounds array access on the line

> let received = transport.protocolMessagesReceived.filter { $0.action == .presence }[0].presence![0]

I’m speculating that this failure is caused by the same thing as in
57b7266, 3f155f9, and 7c53cec - that is, that a .present is received
instead of a .enter, causing the array to be empty (it is certainly
vulnerable to this problem) - and hence am attempting the same fix.

I’ve also swapped around the order of subscribing and publishing -
although it probably doesn’t make a difference in reality since there’s
asynchronous work involved in the publishing, conceptually it makes
sense to subscribe before publishing.

Test case:
https://test-observability.herokuapp.com/repos/ably/ably-cocoa/test_cases/ac44f09c-f521-4bfc-a3d7-58d4f7428c74

Example failure:
https://test-observability.herokuapp.com/repos/ably/ably-cocoa/failures/ac72c3e0-1211-4a1d-9a13-c62189734341

Closes #1333.
  • Loading branch information
lawrence-forooghian committed May 5, 2022
1 parent 7c53cec commit a967b2d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Spec/Tests/RealtimeClientPresenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1094,18 +1094,23 @@ class RealtimeClientPresenceTests: XCTestCase {
let client = AblyTests.newRealtime(options)
defer { client.dispose(); client.close() }
let channel = client.channels.get(uniqueChannelName())
// We want to make sure that the ENTER presence action that we publish
// gets sent by Realtime as a PRESENCE protocol message, and not in the
// channel’s initial post-attach SYNC. So, we wait for any initial SYNC
// to complete before publishing any presence actions.
attachAndWaitForInitialPresenceSyncToComplete(client: client, channel: channel)

waitUntil(timeout: testTimeout) { done in
let partialDone = AblyTests.splitDone(2, done: done)
channel.presence.enter("online") { error in
expect(error).to(beNil())
partialDone()
}
channel.presence.subscribe { message in
channel.presence.subscribe(.enter) { message in
expect(message.clientId).to(equal("john"))
channel.presence.unsubscribe()
partialDone()
}
channel.presence.enter("online") { error in
expect(error).to(beNil())
partialDone()
}
}

let transport = client.internal.transport as! TestProxyTransport
Expand Down

0 comments on commit a967b2d

Please sign in to comment.