@@ -7,6 +7,7 @@ import NextcloudCapabilitiesKit
77@testable import NextcloudFileProviderKit
88import NextcloudFileProviderKitMocks
99import RealmSwift
10+ import Testing
1011import TestInterface
1112import XCTest
1213
@@ -402,27 +403,12 @@ final class RemoteChangeObserverTests: NextcloudFileProviderKitTestCase {
402403 }
403404
404405 func testPinging( ) async throws {
406+ let authenticated = expectation ( description: " authenticated " )
405407 let remoteInterface = MockRemoteInterface ( account: Self . account)
406408 remoteInterface. capabilities = mockCapabilities
407409
408- actor AuthFlag {
409- var value = false
410- func set( ) {
411- value = true
412- }
413-
414- func get( ) -> Bool {
415- value
416- }
417- }
418- let authenticated = AuthFlag ( )
419-
420- NotificationCenter . default. addObserver (
421- forName: NotifyPushAuthenticatedNotificationName, object: nil , queue: nil
422- ) { _ in
423- Task {
424- await authenticated. set ( )
425- }
410+ NotificationCenter . default. addObserver ( forName: NotifyPushAuthenticatedNotificationName, object: nil , queue: nil ) { _ in
411+ authenticated. fulfill ( )
426412 }
427413
428414 remoteChangeObserver = RemoteChangeObserver (
@@ -437,20 +423,14 @@ final class RemoteChangeObserverTests: NextcloudFileProviderKitTestCase {
437423 let pingIntervalNsecs = 500_000_000
438424 remoteChangeObserver? . setWebSocketPingInterval ( to: UInt64 ( pingIntervalNsecs) )
439425
440- for _ in 0 ... Self . timeout {
441- try await Task . sleep ( nanoseconds: 1_000_000 )
442- if await authenticated. get ( ) {
443- break
444- }
445- }
446- let isAuthenticated = await authenticated. get ( )
447- XCTAssertTrue ( isAuthenticated)
426+ await fulfillment ( of: [ authenticated] )
448427
449428 let intendedPings = 3
450429 // Add a bit of buffer to the wait time
451- let intendedPingsWait = ( intendedPings + 1 ) * pingIntervalNsecs
430+ let intendedPingsWait = ( intendedPings + 2 ) * pingIntervalNsecs
452431
453432 var pings = 0
433+
454434 Self . notifyPushServer. pingHandler = {
455435 pings += 1
456436 }
0 commit comments