@@ -11,6 +11,7 @@ import XCTest
1111 import FoundationNetworking
1212#endif
1313
14+ @MainActor
1415final class RealtimeTests : XCTestCase {
1516 let url = URL ( string: " http://localhost:54321/realtime/v1 " ) !
1617 let apiKey = " anon.api.key "
@@ -33,8 +34,8 @@ final class RealtimeTests: XCTestCase {
3334 let reconnectDelay : TimeInterval = RealtimeClientOptions . defaultReconnectDelay
3435 let timeoutInterval : TimeInterval = RealtimeClientOptions . defaultTimeoutInterval
3536
36- override func setUp( ) {
37- super. setUp ( )
37+ override func setUp( ) async throws {
38+ try await super. setUp ( )
3839
3940 ( client, server) = FakeWebSocket . fakes ( )
4041 http = HTTPClientMock ( )
@@ -54,10 +55,10 @@ final class RealtimeTests: XCTestCase {
5455 )
5556 }
5657
57- override func tearDown( ) {
58+ override func tearDown( ) async throws {
5859 sut. disconnect ( )
5960
60- super. tearDown ( )
61+ try await super. tearDown ( )
6162 }
6263
6364 func test_transport( ) async {
@@ -128,10 +129,10 @@ final class RealtimeTests: XCTestCase {
128129
129130 XCTAssertEqual ( socketStatuses. value, [ . disconnected, . connecting, . connected] )
130131
131- let messageTask = sut. mutableState . messageTask
132+ let messageTask = sut. messageTask
132133 XCTAssertNotNil ( messageTask)
133134
134- let heartbeatTask = sut. mutableState . heartbeatTask
135+ let heartbeatTask = sut. heartbeatTask
135136 XCTAssertNotNil ( heartbeatTask)
136137
137138 let channelStatuses = LockIsolated ( [ RealtimeChannelStatus] ( ) )
@@ -247,15 +248,22 @@ final class RealtimeTests: XCTestCase {
247248 // So we need to wait at least 2.5s to ensure the retry happens
248249 await testClock. advance ( by: . seconds( 2.5 ) )
249250
250- let events = client. sentEvents. compactMap { $0. realtimeMessage } . filter {
251- $0. event == " phx_join "
252- }
253- assertInlineSnapshot ( of: events, as: . json) {
251+ let events = client. sentEvents. compactMap { $0. realtimeMessage }
252+
253+ assertInlineSnapshot ( of: events, as: . json, record: . failed) {
254254 #"""
255255 [
256+ {
257+ "event" : "heartbeat",
258+ "payload" : {
259+
260+ },
261+ "ref" : "1",
262+ "topic" : "phoenix"
263+ },
256264 {
257265 "event" : "phx_join",
258- "join_ref" : "1 ",
266+ "join_ref" : "2 ",
259267 "payload" : {
260268 "access_token" : "custom.access.token",
261269 "config" : {
@@ -274,12 +282,12 @@ final class RealtimeTests: XCTestCase {
274282 },
275283 "version" : "realtime-swift\/0.0.0"
276284 },
277- "ref" : "1 ",
285+ "ref" : "2 ",
278286 "topic" : "realtime:public:messages"
279287 },
280288 {
281289 "event" : "phx_join",
282- "join_ref" : "2 ",
290+ "join_ref" : "3 ",
283291 "payload" : {
284292 "access_token" : "custom.access.token",
285293 "config" : {
@@ -298,7 +306,7 @@ final class RealtimeTests: XCTestCase {
298306 },
299307 "version" : "realtime-swift\/0.0.0"
300308 },
301- "ref" : "2 ",
309+ "ref" : "3 ",
302310 "topic" : "realtime:public:messages"
303311 }
304312 ]
@@ -524,7 +532,7 @@ final class RealtimeTests: XCTestCase {
524532
525533 await fulfillment ( of: [ sentHeartbeatExpectation] , timeout: 0 )
526534
527- let pendingHeartbeatRef = sut. mutableState . pendingHeartbeatRef
535+ let pendingHeartbeatRef = sut. pendingHeartbeatRef
528536 XCTAssertNotNil ( pendingHeartbeatRef)
529537
530538 // Wait until next heartbeat
@@ -614,7 +622,7 @@ final class RealtimeTests: XCTestCase {
614622 " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjY0MDkyMjExMjAwfQ.GfiEKLl36X8YWcatHg31jRbilovlGecfUKnOyXMSX9c "
615623 await sut. setAuth ( validToken)
616624
617- XCTAssertEqual ( sut. mutableState . accessToken, validToken)
625+ XCTAssertEqual ( sut. accessToken, validToken)
618626 }
619627
620628 func testSetAuthWithNonJWT( ) async throws {
0 commit comments