Skip to content

Commit a1156b1

Browse files
committed
fix(tests): Replaced constant time delays with expectations.
Otherwise the affected test fails in GitHub actions due to the hosted Action runners being significantly slower. Signed-off-by: Iva Horn <[email protected]>
1 parent f30c0b5 commit a1156b1

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

Sources/NextcloudFileProviderKit/Enumeration/RemoteChangeObserver.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,18 @@ public class RemoteChangeObserver: NSObject, NextcloudKitDelegate, URLSessionWeb
467467
_ request: Alamofire.DataRequest, didParseResponse response: Alamofire.AFDataResponse<Value>
468468
) { }
469469

470-
func startWorkingSetCheck() {
470+
///
471+
/// Dispatches the asynchronous working set check.
472+
///
473+
/// - Parameters:
474+
/// - completionHandler: An optional closure to call after the working set check completed.
475+
///
476+
func startWorkingSetCheck(completionHandler: (() -> Void)? = nil) {
471477
guard !workingSetCheckOngoing, !invalidated else { return }
472-
Task { await checkWorkingSet() }
478+
Task {
479+
await checkWorkingSet()
480+
completionHandler?()
481+
}
473482
}
474483

475484
private func checkWorkingSet() async {

Tests/NextcloudFileProviderKitTests/RemoteChangeObserverEtagOptimizationTests.swift

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,33 @@ final class RemoteChangeObserverEtagOptimizationTests: XCTestCase {
126126
print("\n=== Running multiple working set checks ===")
127127

128128
// First working set check
129-
remoteChangeObserver.startWorkingSetCheck()
130-
try await Task.sleep(nanoseconds: 100_000_000) // 0.1 seconds
129+
var workingSetCheckCompleted = expectation(description: "First working set check completed.")
130+
131+
remoteChangeObserver.startWorkingSetCheck {
132+
workingSetCheckCompleted.fulfill()
133+
}
134+
135+
await fulfillment(of: [workingSetCheckCompleted])
131136

132137
// Second working set check (simulating rapid notify_file messages)
133-
remoteChangeObserver.startWorkingSetCheck()
134-
try await Task.sleep(nanoseconds: 100_000_000) // 0.1 seconds
138+
workingSetCheckCompleted = expectation(description: "Second working set check completed.")
139+
140+
remoteChangeObserver.startWorkingSetCheck {
141+
workingSetCheckCompleted.fulfill()
142+
}
143+
144+
await fulfillment(of: [workingSetCheckCompleted])
135145

136146
// Third working set check
137-
remoteChangeObserver.startWorkingSetCheck()
138-
try await Task.sleep(nanoseconds: 100_000_000) // 0.1 seconds
147+
workingSetCheckCompleted = expectation(description: "Third working set check completed.")
148+
149+
remoteChangeObserver.startWorkingSetCheck {
150+
workingSetCheckCompleted.fulfill()
151+
}
152+
153+
await fulfillment(of: [workingSetCheckCompleted])
139154

140155
// Wait for all operations to complete
141-
try await Task.sleep(nanoseconds: 500_000_000) // 0.5 seconds
142156

143157
print("\n=== Results ===")
144158
print("Total enumerate calls: \(enumerateCallCount)")

0 commit comments

Comments
 (0)