Skip to content

Commit 673f497

Browse files
committed
fix: Refactored failing test.
Signed-off-by: Iva Horn <iva.horn@nextcloud.com>
1 parent 995f249 commit 673f497

1 file changed

Lines changed: 9 additions & 27 deletions

File tree

Tests/NextcloudFileProviderKitTests/RemoteChangeObserverTests.swift

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import NextcloudCapabilitiesKit
77
@testable import NextcloudFileProviderKit
88
import NextcloudFileProviderKitMocks
99
import RealmSwift
10+
import Testing
1011
import TestInterface
1112
import XCTest
1213

@@ -50,7 +51,7 @@ final class RemoteChangeObserverTests: NextcloudFileProviderKitTestCase {
5051

5152
/// Helper to wait for an expectation with a standard timeout.
5253
private func wait(for expectation: XCTestExpectation, description: String) async {
53-
let result = await XCTWaiter.fulfillment(of: [expectation], timeout: 5.0)
54+
let result = await XCTWaiter.fulfillment(of: [expectation], timeout: 10.0)
5455
if result != .completed {
5556
XCTFail("Timeout waiting for \(description)")
5657
}
@@ -402,27 +403,14 @@ final class RemoteChangeObserverTests: NextcloudFileProviderKitTestCase {
402403
}
403404

404405
func testPinging() async throws {
406+
let authenticated = expectation(description: "authenticated")
407+
authenticated.assertForOverFulfill = false
408+
405409
let remoteInterface = MockRemoteInterface(account: Self.account)
406410
remoteInterface.capabilities = mockCapabilities
407411

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-
}
412+
NotificationCenter.default.addObserver(forName: NotifyPushAuthenticatedNotificationName, object: nil, queue: nil) { _ in
413+
authenticated.fulfill()
426414
}
427415

428416
remoteChangeObserver = RemoteChangeObserver(
@@ -437,20 +425,14 @@ final class RemoteChangeObserverTests: NextcloudFileProviderKitTestCase {
437425
let pingIntervalNsecs = 500_000_000
438426
remoteChangeObserver?.setWebSocketPingInterval(to: UInt64(pingIntervalNsecs))
439427

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)
428+
await fulfillment(of: [authenticated])
448429

449430
let intendedPings = 3
450431
// Add a bit of buffer to the wait time
451432
let intendedPingsWait = (intendedPings + 1) * pingIntervalNsecs
452433

453434
var pings = 0
435+
454436
Self.notifyPushServer.pingHandler = {
455437
pings += 1
456438
}

0 commit comments

Comments
 (0)