Skip to content

Commit

Permalink
Added timestamps to assert client left in between main client suspend…
Browse files Browse the repository at this point in the history
…ed and re-attached events.
  • Loading branch information
maratal committed Oct 14, 2023
1 parent 9a11e43 commit 208c794
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Test/Tests/RealtimeClientPresenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,10 @@ class RealtimeClientPresenceTests: XCTestCase {
}

var presenceEvents = [ARTPresenceMessage]()

var mainSuspendedAt = Date()
var mainAttachedAt = Date()
var clientLeftAt = Date()

waitUntil(timeout: testTimeout) { done in
let partialDone = AblyTests.splitDone(4, done: done)
mainChannel.presence.subscribe { presence in
Expand All @@ -823,19 +826,21 @@ class RealtimeClientPresenceTests: XCTestCase {
}
}
mainChannel.once(.suspended) { _ in
mainSuspendedAt = Date()
mainChannel.internalSync { _internal in
XCTAssertEqual(_internal.presenceMap.members.count, 4) // "main", "user1", "user2", "leaves"
XCTAssertEqual(_internal.presenceMap.localMembers.count, 1) // "main"
}
leavesChannel.presence.leave(nil) { error in
XCTAssertNil(error)
XCTAssertEqual(mainChannel.state, .suspended)
clientLeftAt = Date()
partialDone()
}
partialDone()
}
mainChannel.once(.attached) { stateChange in
XCTAssertNil(stateChange.reason)
mainAttachedAt = Date()
partialDone()
}
mainChannel.internalAsync { _internal in
Expand All @@ -845,6 +850,9 @@ class RealtimeClientPresenceTests: XCTestCase {
XCTAssertEqual(presenceEvents.count, 1)
XCTAssertEqual(presenceEvents[0].action, ARTPresenceAction.leave)
XCTAssertEqual(presenceEvents[0].clientId, "leaves")

XCTAssertTrue(mainSuspendedAt < clientLeftAt)
XCTAssertTrue(clientLeftAt < mainAttachedAt)

mainChannel.presence.unsubscribe()

Expand Down

0 comments on commit 208c794

Please sign in to comment.