Skip to content

Commit 2abefd9

Browse files
committed
Work in progress: Fixing tests.
Signed-off-by: Iva Horn <iva.horn@nextcloud.com>
1 parent 53d442d commit 2abefd9

4 files changed

Lines changed: 20 additions & 17 deletions

File tree

Sources/NextcloudFileProviderKit/Enumeration/RemoteChangeObserver.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,18 @@ public actor RemoteChangeObserver: NSObject, Sendable {
126126
private func reconnectWebSocket() {
127127
stopPollingTimer()
128128
resetWebSocket()
129+
129130
guard networkReachability != .notReachable else {
130131
logger.error("Network unreachable, will retry when reconnected.")
131132
return
132133
}
134+
133135
guard webSocketAuthenticationFailCount < webSocketAuthenticationFailLimit else {
134136
logger.error("Exceeded authentication failures for notify push websocket \(account.ncKitAccount), will poll instead.", [.account: account.ncKitAccount])
135137
startPollingTimer()
136138
return
137139
}
140+
138141
Task { [weak self] in
139142
try await Task.sleep(nanoseconds: self?.webSocketReconfigureIntervalNanoseconds ?? 0)
140143
await self?.configureNotifyPush()

Tests/Interface/MockNotifyPushServer.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ public class MockNotifyPushServer: @unchecked Sendable {
6060
public func run() async throws {
6161
let channel: NIOAsyncChannel<EventLoopFuture<UpgradeResult>, Never> = try await ServerBootstrap(group: eventLoopGroup)
6262
.serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1)
63-
.bind(
64-
host: host,
65-
port: port
66-
) { channel in
63+
.bind(host: host, port: port) { channel in
6764
channel.eventLoop.makeCompletedFuture {
6865
let upgrader = NIOTypedWebSocketServerUpgrader<UpgradeResult>(
6966
shouldUpgrade: { channel, _ in

Tests/NextcloudFileProviderKitTests/RemoteChangeObserverTests.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ final class RemoteChangeObserverTests: NextcloudFileProviderKitTestCase {
3535

3636
override func setUp() async throws {
3737
Realm.Configuration.defaultConfiguration.inMemoryIdentifier = name
38-
try await Self.notifyPushServer.run()
38+
let server = Self.notifyPushServer
39+
40+
Task {
41+
try await server.run()
42+
}
3943
}
4044

4145
override func tearDown() async throws {
@@ -57,6 +61,7 @@ final class RemoteChangeObserverTests: NextcloudFileProviderKitTestCase {
5761
remoteInterface.capabilities = mockCapabilities
5862

5963
let authenticated = expectation(description: "authenticated")
64+
authenticated.assertForOverFulfill = false
6065

6166
NotificationCenter.default.addObserver(forName: NotifyPushAuthenticatedNotificationName, object: nil, queue: nil) { _ in
6267
authenticated.fulfill()

Tests/NextcloudFileProviderKitTests/RemoteInterfaceTests.swift

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,7 @@ struct RemoteInterfaceExtensionTests {
130130
}
131131

132132
// 1. Simulate an external process starting a fetch for testAccount
133-
await RetrievedCapabilitiesActor.shared.setOngoingFetch(
134-
forAccount: testAccount.ncKitAccount, ongoing: true
135-
)
133+
await RetrievedCapabilitiesActor.shared.setOngoingFetch(forAccount: testAccount.ncKitAccount, ongoing: true)
136134

137135
await confirmation("currentCapabilitiesReturned") { currentCapabilitiesReturned in
138136
let currentCapabilitiesTask = Task { @Sendable in
@@ -144,17 +142,17 @@ struct RemoteInterfaceExtensionTests {
144142
#expect(result.error == .success)
145143
}
146144

147-
await currentCapabilitiesTask.value
148-
}
145+
// 3. Now, the "external" fetch completes and populates the cache.
146+
await RetrievedCapabilitiesActor.shared.setCapabilities(
147+
forAccount: testAccount.ncKitAccount,
148+
capabilities: cachedCaps,
149+
retrievedAt: Date() // Fresh date
150+
)
149151

150-
// 4. Now, the "external" fetch completes and populates the cache.
151-
await RetrievedCapabilitiesActor.shared.setCapabilities(
152-
forAccount: testAccount.ncKitAccount,
153-
capabilities: cachedCaps,
154-
retrievedAt: Date() // Fresh date
155-
)
152+
await RetrievedCapabilitiesActor.shared.setOngoingFetch(forAccount: testAccount.ncKitAccount, ongoing: false)
156153

157-
await RetrievedCapabilitiesActor.shared.setOngoingFetch(forAccount: testAccount.ncKitAccount, ongoing: false)
154+
await currentCapabilitiesTask.value
155+
}
158156
}
159157

160158
@Test func supportsTrashTrue() async throws {

0 commit comments

Comments
 (0)