1
1
import XCTest
2
- import Combine
2
+ @ preconcurrency import Combine
3
3
#if os(iOS)
4
4
import CoreTelephony
5
5
#endif
@@ -15,8 +15,7 @@ final class ReachabilityTests: XCTestCase {
15
15
bag. removeAll ( )
16
16
}
17
17
18
- @MainActor
19
- func test_isExpensive_shouldReturnCorrectValue( ) {
18
+ func test_isExpensive_shouldReturnCorrectValue( ) async {
20
19
let path = MockPath ( status: . satisfied, isExpensive: true )
21
20
#if os(iOS)
22
21
let mockTelephonyInfo = MockTelephonyInfo ( )
@@ -25,12 +24,12 @@ final class ReachabilityTests: XCTestCase {
25
24
let monitor = MockPathMonitor ( path: path)
26
25
#endif
27
26
let networkReachability = Reachability ( monitor: monitor)
28
- let isExpensive = networkReachability. isExpensive
27
+ await Task . yield ( )
28
+ let isExpensive = await networkReachability. isExpensive
29
29
XCTAssert ( isExpensive)
30
30
}
31
31
32
- @MainActor
33
- func test_isConstrained_shouldReturnCorrectValue( ) {
32
+ func test_isConstrained_shouldReturnCorrectValue( ) async {
34
33
let path = MockPath ( status: . satisfied, isConstrained: true )
35
34
#if os(iOS)
36
35
let mockTelephonyInfo = MockTelephonyInfo ( )
@@ -39,12 +38,12 @@ final class ReachabilityTests: XCTestCase {
39
38
let monitor = MockPathMonitor ( path: path)
40
39
#endif
41
40
let networkReachability = Reachability ( monitor: monitor)
42
- let isConstrained = networkReachability. isConstrained
41
+ await Task . yield ( )
42
+ let isConstrained = await networkReachability. isConstrained
43
43
XCTAssert ( isConstrained)
44
44
}
45
45
46
- @MainActor
47
- func test_status_shouldReturnConnectionStatus( ) {
46
+ func test_status_shouldReturnConnectionStatus( ) async {
48
47
let path = MockPath ( status: . satisfied, availableInterfaceTypes: . wifi)
49
48
#if os(iOS)
50
49
let mockTelephonyInfo = MockTelephonyInfo ( )
@@ -53,11 +52,11 @@ final class ReachabilityTests: XCTestCase {
53
52
let monitor = MockPathMonitor ( path: path)
54
53
#endif
55
54
let networkReachability = Reachability ( monitor: monitor)
56
- let connectionStatus = networkReachability. status
55
+ await Task . yield ( )
56
+ let connectionStatus = await networkReachability. status
57
57
XCTAssertEqual ( connectionStatus, . connected( . wifi) )
58
58
}
59
59
60
- @MainActor
61
60
func test_changes_whenConnectionStatusChanges_shouldNotify( ) async {
62
61
let path = MockPath ( status: . satisfied, availableInterfaceTypes: . wifi)
63
62
#if os(iOS)
@@ -67,6 +66,7 @@ final class ReachabilityTests: XCTestCase {
67
66
let monitor = MockPathMonitor ( path: path)
68
67
#endif
69
68
let networkReachability = Reachability ( monitor: monitor)
69
+ await Task . yield ( )
70
70
let expectation = XCTestExpectation ( description: " connection status changed " )
71
71
Task . detached {
72
72
for await status in await networkReachability. changes ( ) {
@@ -90,7 +90,6 @@ final class ReachabilityTests: XCTestCase {
90
90
await fulfillment ( of: [ expectation] )
91
91
}
92
92
93
- @MainActor
94
93
func test_changesPublisher_whenConnectionStatusChanges_shouldNotify( ) async {
95
94
let path = MockPath ( status: . satisfied, availableInterfaceTypes: . wifi)
96
95
#if os(iOS)
@@ -100,8 +99,10 @@ final class ReachabilityTests: XCTestCase {
100
99
let monitor = MockPathMonitor ( path: path)
101
100
#endif
102
101
let networkReachability = Reachability ( monitor: monitor)
102
+ await Task . yield ( )
103
103
let expectation = XCTestExpectation ( description: " connection status changed " )
104
- networkReachability. changesPublisher ( ) . sink { status in
104
+ let publisher = await networkReachability. changesPublisher ( )
105
+ publisher. sink { status in
105
106
#if os(iOS)
106
107
XCTAssertEqual ( status, . connected( . cellular( . cellular4G) ) )
107
108
#else
@@ -121,7 +122,6 @@ final class ReachabilityTests: XCTestCase {
121
122
await fulfillment ( of: [ expectation] )
122
123
}
123
124
124
- @MainActor
125
125
func test_changes_whenConnectionStatusDidNotChange_shouldNotNotify( ) async {
126
126
let path = MockPath ( status: . satisfied, availableInterfaceTypes: . wifi)
127
127
#if os(iOS)
@@ -131,6 +131,7 @@ final class ReachabilityTests: XCTestCase {
131
131
let monitor = MockPathMonitor ( path: path)
132
132
#endif
133
133
let networkReachability = Reachability ( monitor: monitor)
134
+ await Task . yield ( )
134
135
let expectation = XCTestExpectation ( description: " connection status changed " )
135
136
Task . detached {
136
137
for await status in await networkReachability. changes ( ) {
@@ -156,7 +157,6 @@ final class ReachabilityTests: XCTestCase {
156
157
await fulfillment ( of: [ expectation] )
157
158
}
158
159
159
- @MainActor
160
160
func test_changesPublisher_whenConnectionStatusDidNotChange_shouldNotNotify( ) async {
161
161
let path = MockPath ( status: . satisfied, availableInterfaceTypes: . wifi)
162
162
#if os(iOS)
@@ -166,8 +166,10 @@ final class ReachabilityTests: XCTestCase {
166
166
let monitor = MockPathMonitor ( path: path)
167
167
#endif
168
168
let networkReachability = Reachability ( monitor: monitor)
169
+ await Task . yield ( )
169
170
let expectation = XCTestExpectation ( description: " connection status changed " )
170
- networkReachability. changesPublisher ( ) . sink { status in
171
+ let publisher = await networkReachability. changesPublisher ( )
172
+ publisher. sink { status in
171
173
#if os(iOS)
172
174
XCTAssertEqual ( status, . connected( . cellular( . cellular4G) ) )
173
175
#else
@@ -189,7 +191,6 @@ final class ReachabilityTests: XCTestCase {
189
191
await fulfillment ( of: [ expectation] )
190
192
}
191
193
192
- @MainActor
193
194
func test_expensiveChanges_whenCostChanges_shouldNotify( ) async {
194
195
let path = MockPath ( status: . satisfied, isExpensive: true )
195
196
#if os(iOS)
@@ -199,6 +200,7 @@ final class ReachabilityTests: XCTestCase {
199
200
let monitor = MockPathMonitor ( path: path)
200
201
#endif
201
202
let networkReachability = Reachability ( monitor: monitor)
203
+ await Task . yield ( )
202
204
let expectation = XCTestExpectation ( description: " cost changed " )
203
205
Task . detached {
204
206
for await isExpensive in await networkReachability. expensiveChanges ( ) {
@@ -214,7 +216,6 @@ final class ReachabilityTests: XCTestCase {
214
216
await fulfillment ( of: [ expectation] )
215
217
}
216
218
217
- @MainActor
218
219
func test_expensiveChangesPublisher_whenCostChanges_shouldNotify( ) async {
219
220
let path = MockPath ( status: . satisfied, isExpensive: true )
220
221
#if os(iOS)
@@ -224,8 +225,10 @@ final class ReachabilityTests: XCTestCase {
224
225
let monitor = MockPathMonitor ( path: path)
225
226
#endif
226
227
let networkReachability = Reachability ( monitor: monitor)
228
+ await Task . yield ( )
227
229
let expectation = XCTestExpectation ( description: " cost changed " )
228
- networkReachability. expensiveChangesPublisher ( ) . sink { isExpensive in
230
+ let publisher = await networkReachability. expensiveChangesPublisher ( )
231
+ publisher. sink { isExpensive in
229
232
XCTAssertFalse ( isExpensive)
230
233
expectation. fulfill ( )
231
234
} . store ( in: & bag)
@@ -237,7 +240,6 @@ final class ReachabilityTests: XCTestCase {
237
240
await fulfillment ( of: [ expectation] )
238
241
}
239
242
240
- @MainActor
241
243
func test_constrainedChanges_whenRestrictionsChanges_shouldNotify( ) async {
242
244
let path = MockPath ( status: . satisfied, isConstrained: true )
243
245
#if os(iOS)
@@ -247,6 +249,7 @@ final class ReachabilityTests: XCTestCase {
247
249
let monitor = MockPathMonitor ( path: path)
248
250
#endif
249
251
let networkReachability = Reachability ( monitor: monitor)
252
+ await Task . yield ( )
250
253
let expectation = XCTestExpectation ( description: " restriction changed " )
251
254
Task . detached {
252
255
for await isConstrained in await networkReachability. constrainedChanges ( ) {
@@ -262,7 +265,6 @@ final class ReachabilityTests: XCTestCase {
262
265
await fulfillment ( of: [ expectation] )
263
266
}
264
267
265
- @MainActor
266
268
func test_constrainedChangesPublisher_whenRestrictionsChanges_shouldNotify( ) async {
267
269
let path = MockPath ( status: . satisfied, isConstrained: true )
268
270
#if os(iOS)
@@ -272,8 +274,10 @@ final class ReachabilityTests: XCTestCase {
272
274
let monitor = MockPathMonitor ( path: path)
273
275
#endif
274
276
let networkReachability = Reachability ( monitor: monitor)
277
+ await Task . yield ( )
275
278
let expectation = XCTestExpectation ( description: " restriction changed " )
276
- networkReachability. constrainedChangesPublisher ( ) . sink { isConstrained in
279
+ let publisher = await networkReachability. constrainedChangesPublisher ( )
280
+ publisher. sink { isConstrained in
277
281
XCTAssertFalse ( isConstrained)
278
282
expectation. fulfill ( )
279
283
} . store ( in: & bag)
0 commit comments