File tree Expand file tree Collapse file tree
OpenHABCore/Tests/OpenHABCoreTests Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -155,19 +155,18 @@ final class NetworkTrackerTests: XCTestCase {
155155 failureTracker: ConnectionFailureTracker ( )
156156 )
157157
158- let tracker = MainActorNetworkTracker ( tracker: networkTracker)
159-
160- var cancellables = Set < AnyCancellable > ( )
161-
162- tracker. $status
163- . sink { status in
158+ // Subscribe directly to NetworkTracker's statusStream to avoid race conditions
159+ // with MainActorNetworkTracker's async Task initialization
160+ let statusTask = Task {
161+ for await status in await networkTracker. statusStream ( ) {
164162 Logger . testNetworkTracker
165163 . info ( " NetworkTrackerTests: Network status became \( status == . connected ? " connected " : ( status == . connecting ? " connecting " : ( status == . started ? " started " : " stopped " ) ) ) " )
166164 if status == . connected {
167165 expectation. fulfill ( )
166+ break
168167 }
169168 }
170- . store ( in : & cancellables )
169+ }
171170
172171 // Start tracking with your mock config
173172 await networkTracker. startTracking ( connectionConfigurations: [ config] )
@@ -176,6 +175,7 @@ final class NetworkTrackerTests: XCTestCase {
176175 mockMonitor. simulateConnection ( isConnected: true )
177176
178177 await fulfillment ( of: [ expectation] , timeout: 2.0 )
178+ statusTask. cancel ( )
179179 }
180180
181181// @MainActor
You can’t perform that action at this time.
0 commit comments