Skip to content

Commit 9ab9ad9

Browse files
committed
Work in progress: Fixed some compiler errors.
Signed-off-by: Iva Horn <iva.horn@nextcloud.com>
1 parent c8d5a13 commit 9ab9ad9

6 files changed

Lines changed: 138 additions & 170 deletions

File tree

Sources/NextcloudFileProviderKit/Enumeration/RemoteChangeObserver.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public actor RemoteChangeObserver: NSObject, Sendable {
1818
private(set) var account: Account
1919
public var accountId: String { account.ncKitAccount }
2020

21-
public let webSocketPingIntervalNanoseconds: UInt64 = 3 * 1_000_000_000
21+
public var webSocketPingIntervalNanoseconds: UInt64 = 3 * 1_000_000_000
2222
public let webSocketReconfigureIntervalNanoseconds: UInt64 = 1 * 1_000_000_000
2323
public let webSocketPingFailLimit = 8
2424
public let webSocketAuthenticationFailLimit = 3
@@ -40,7 +40,8 @@ public actor RemoteChangeObserver: NSObject, Sendable {
4040
private(set) var webSocketAuthenticationFailCount = 0
4141

4242
private(set) var pollingTimer: Timer?
43-
public var pollInterval: TimeInterval = 60 {
43+
44+
private(set) var pollInterval: TimeInterval = 60 {
4445
didSet {
4546
if pollingActive {
4647
stopPollingTimer()
@@ -364,6 +365,14 @@ public actor RemoteChangeObserver: NSObject, Sendable {
364365
func replaceAccount(with account: Account) {
365366
self.account = account
366367
}
368+
369+
func setPollInterval(to interval: TimeInterval) {
370+
self.pollInterval = interval
371+
}
372+
373+
func setWebSocketPingInterval(to nanoseconds: UInt64) {
374+
self.webSocketPingIntervalNanoseconds = nanoseconds
375+
}
367376
}
368377

369378
// MARK: - URLSessionWebSocketDelegate

Sources/NextcloudFileProviderKitMocks/TestableRemoteInterface.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ import NextcloudCapabilitiesKit
88
import NextcloudKit
99

1010
public struct TestableRemoteInterface: RemoteInterface, @unchecked Sendable {
11-
public init() {}
11+
public typealias FetchCapabilitiesHandler = @Sendable (Account, NKRequestOptions, @Sendable @escaping (URLSessionTask) -> Void) async -> FetchResult
12+
13+
public let fetchCapabilitiesHandler: FetchCapabilitiesHandler?
14+
15+
public init(fetchCapabilitiesHandler: FetchCapabilitiesHandler?) {
16+
self.fetchCapabilitiesHandler = fetchCapabilitiesHandler
17+
}
1218

1319
public func setDelegate(_: any NextcloudKitDelegate) {}
1420

@@ -171,8 +177,6 @@ public struct TestableRemoteInterface: RemoteInterface, @unchecked Sendable {
171177

172178
public typealias FetchResult = (account: String, capabilities: Capabilities?, data: Data?, error: NKError)
173179

174-
public var fetchCapabilitiesHandler: (@Sendable (Account, NKRequestOptions, @Sendable @escaping (URLSessionTask) -> Void) async -> FetchResult)?
175-
176180
public func fetchCapabilities(
177181
account: Account,
178182
options: NKRequestOptions = .init(),

Tests/NextcloudFileProviderKitTests/EnumeratorTests.swift

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,7 @@ final class EnumeratorTests: NextcloudFileProviderKitTestCase {
310310
// --- Scenario A: Initial Paginated Request (isFollowUpPaginatedRequest == false) ---
311311

312312
// 2. Act: Call readServerUrl for the first page.
313-
let (
314-
initialMetadatas, _, _, _, initialNextPage, initialError
315-
) = await Enumerator.readServerUrl(
313+
let (initialMetadatas, _, _, _, initialNextPage, initialError) = await Enumerator.readServerUrl(
316314
remoteFolder.remotePath,
317315
pageSettings: (page: nil, index: 0, size: 5), // index is 0
318316
account: Self.account,
@@ -324,6 +322,7 @@ final class EnumeratorTests: NextcloudFileProviderKitTestCase {
324322
// 3. Assert: Verify the initial request's behavior.
325323
XCTAssertNil(initialError)
326324
XCTAssertNotNil(initialNextPage, "Should receive a next page token for the initial request")
325+
327326
// The first request for a folder returns the folder itself plus the first page of children.
328327
XCTAssertEqual(
329328
initialMetadatas?.count,
@@ -334,27 +333,21 @@ final class EnumeratorTests: NextcloudFileProviderKitTestCase {
334333
so count is (4).
335334
"""
336335
)
337-
XCTAssertFalse(
338-
initialMetadatas?.contains(where: { $0.ocId == remoteFolder.identifier }) ?? false,
339-
"The folder itself should not be in the initial results."
340-
)
336+
337+
XCTAssertFalse(initialMetadatas?.contains(where: { $0.ocId == remoteFolder.identifier }) ?? false, "The folder itself should not be in the initial results.")
341338

342339
// The logic inside `if !isFollowUpPaginatedRequest` should have run,
343340
// updating the folder's metadata.
344-
let updatedFolderMetadata =
345-
try XCTUnwrap(Self.dbManager.itemMetadata(ocId: remoteFolder.identifier))
346-
XCTAssertNotEqual(
347-
updatedFolderMetadata.etag, oldEtag, "The folder's etag should have been updated."
348-
)
341+
let updatedFolderMetadata = try XCTUnwrap(Self.dbManager.itemMetadata(ocId: remoteFolder.identifier))
342+
XCTAssertNotEqual(updatedFolderMetadata.etag, oldEtag, "The folder's etag should have been updated.")
349343
XCTAssertEqual(updatedFolderMetadata.etag, remoteFolder.versionIdentifier)
350344

351345
// --- Scenario B: Follow-up Paginated Request (isFollowUpPaginatedRequest == true) ---
352346

353347
// 4. Act: Call readServerUrl for the second page using the received page token.
354348
let followUpPage = NSFileProviderPage(initialNextPage!.token!.data(using: .utf8)!)
355-
let (
356-
followUpMetadatas, _, _, _, finalNextPage, followUpError
357-
) = await Enumerator.readServerUrl(
349+
350+
let (followUpMetadatas, _, _, _, finalNextPage, followUpError) = await Enumerator.readServerUrl(
358351
remoteFolder.remotePath,
359352
pageSettings: (page: followUpPage, index: 1, size: 5), // index > 0 and page is non-nil
360353
account: Self.account,

Tests/NextcloudFileProviderKitTests/FilesDatabaseManagerTests.swift

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -480,42 +480,6 @@ final class FilesDatabaseManagerTests: NextcloudFileProviderKitTestCase {
480480
XCTAssertTrue(results.updatedMetadatas?.isEmpty ?? true, "No items should have been updated.")
481481
}
482482

483-
func testConcurrencyOnDatabaseWrites() {
484-
let semaphore = DispatchSemaphore(value: 0)
485-
let count = 100
486-
Task {
487-
for i in 0 ... count {
488-
let metadata = SendableItemMetadata(
489-
ocId: "concurrency-\(i)",
490-
fileName: "name",
491-
account: Account(user: "", id: "", serverUrl: "", password: "")
492-
)
493-
Self.dbManager.addItemMetadata(metadata)
494-
}
495-
semaphore.signal()
496-
}
497-
498-
Task {
499-
for i in 0 ... count {
500-
let metadata = SendableItemMetadata(
501-
ocId: "concurrency-\(count + 1 + i)",
502-
fileName: "name",
503-
account: Account(user: "", id: "", serverUrl: "", password: "")
504-
)
505-
Self.dbManager.addItemMetadata(metadata)
506-
}
507-
semaphore.signal()
508-
}
509-
510-
semaphore.wait()
511-
semaphore.wait()
512-
513-
for i in 0 ... count * 2 + 1 {
514-
let resultsI = Self.dbManager.itemMetadata(ocId: "concurrency-\(i)")
515-
XCTAssertNotNil(resultsI, "Metadata \(i) should be saved even under concurrency")
516-
}
517-
}
518-
519483
func testDirectoryMetadataRetrieval() throws {
520484
let account = "TestAccount"
521485
let serverUrl = "https://cloud.example.com/files/documents"

0 commit comments

Comments
 (0)