Skip to content

Commit b6a66fa

Browse files
committed
test: fix realtime tests
1 parent 746f999 commit b6a66fa

File tree

5 files changed

+34
-24
lines changed

5 files changed

+34
-24
lines changed

Sources/Realtime/RealtimeClientV2.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ public final class RealtimeClientV2: RealtimeClientProtocol {
562562
return url
563563
}
564564

565-
var broadcastURL: URL {
565+
nonisolated var broadcastURL: URL {
566566
url.appendingPathComponent("api/broadcast")
567567
}
568568
}

Tests/RealtimeTests/RealtimeChannelTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import XCTestDynamicOverlay
1212

1313
@testable import Realtime
1414

15+
@MainActor
1516
final class RealtimeChannelTests: XCTestCase {
1617
let sut = RealtimeChannelV2(
1718
topic: "topic",

Tests/RealtimeTests/RealtimeTests.swift

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import XCTest
1111
import FoundationNetworking
1212
#endif
1313

14+
@MainActor
1415
final 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 {

Tests/RealtimeTests/_PushTests.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ import XCTest
1212
@testable import Realtime
1313

1414
#if !os(Android) && !os(Linux) && !os(Windows)
15+
@MainActor
1516
final class _PushTests: XCTestCase {
1617
var ws: FakeWebSocket!
1718
var socket: RealtimeClientV2!
1819

19-
override func setUp() {
20-
super.setUp()
20+
override func setUp() async throws {
21+
try await super.setUp()
2122

2223
let (client, server) = FakeWebSocket.fakes()
2324
ws = server
@@ -43,7 +44,7 @@ import XCTest
4344
socket: socket,
4445
logger: nil
4546
)
46-
let push = await PushV2(
47+
let push = PushV2(
4748
channel: channel,
4849
message: RealtimeMessageV2(
4950
joinRef: nil,
@@ -69,7 +70,7 @@ import XCTest
6970
socket: socket,
7071
logger: nil
7172
)
72-
let push = await PushV2(
73+
let push = PushV2(
7374
channel: channel,
7475
message: RealtimeMessageV2(
7576
joinRef: nil,
@@ -84,7 +85,7 @@ import XCTest
8485
await push.send()
8586
}
8687
await Task.megaYield()
87-
await push.didReceive(status: .ok)
88+
push.didReceive(status: .ok)
8889

8990
let status = await task.value
9091
XCTAssertEqual(status, .ok)

Tests/SupabaseTests/SupabaseClientTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ final class SupabaseClientTests: XCTestCase {
8686
let functionsRegion = await client.functions.region
8787
XCTAssertEqual(functionsRegion?.rawValue, "ap-northeast-1")
8888

89-
let realtimeURL = client.realtimeV2.url
89+
let realtimeURL = await client.realtimeV2.url
9090
XCTAssertEqual(realtimeURL.absoluteString, "https://project-ref.supabase.co/realtime/v1")
9191

92-
let realtimeOptions = client.realtimeV2.options
92+
let realtimeOptions = await client.realtimeV2.options
9393
let expectedRealtimeHeader = client._headers.merging(with: [
9494
.init("custom_realtime_header_key")!: "custom_realtime_header_value"
9595
]

0 commit comments

Comments
 (0)