mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-28 16:26:04 +00:00
Stop a failing sync database read from being considered as a successful read.
This commit is contained in:
1 parent
b06be86239
commit
c9bc4f09a1
2 files changed
+56
No files matched your search
@@ -59,4 +59,47 @@ import SyncDatabase
|
||||
let pendingStarredArticleIDs = try #require(await database.selectPendingStarredStatusArticleIDs())
|
||||
#expect(pendingStarredArticleIDs == [articleID])
|
||||
}
|
||||
|
||||
/// The step check must not fire on a healthy read that simply found no rows.
|
||||
/// A false positive there would stop syncing outright.
|
||||
@Test func emptyQueueReadsCleanly() async throws {
|
||||
#expect(try #require(await database.selectForProcessing()).isEmpty)
|
||||
#expect(await database.selectPendingCount() == 0)
|
||||
#expect(try #require(await database.selectPendingReadStatusArticleIDs()).isEmpty)
|
||||
#expect(try #require(await database.selectPendingStarredStatusArticleIDs()).isEmpty)
|
||||
|
||||
// And again once rows have been queued and then cleared.
|
||||
let statuses = Set((0..<5).map { SyncStatus(articleID: "article-\($0)", key: .read, flag: true) })
|
||||
await database.insertStatuses(statuses)
|
||||
_ = await database.selectForProcessing()
|
||||
await database.deleteSelectedForProcessing(Set(statuses.map { $0.articleID }), key: .read)
|
||||
|
||||
#expect(try #require(await database.selectForProcessing()).isEmpty)
|
||||
#expect(await database.selectPendingCount() == 0)
|
||||
}
|
||||
|
||||
/// A read that stops on a SQLite error has to fail, not return the rows it got to
|
||||
/// first. A short pending-statuses read is missing articleIDs that really are
|
||||
/// pending, and the next refresh reverts exactly those edits.
|
||||
///
|
||||
/// This covers failing on the first row. A failure partway through is the same bug
|
||||
/// and the same fix, but there’s no way to force one at a chosen row.
|
||||
@Test func aReadThatStopsOnAnErrorFails() async throws {
|
||||
let folderURL = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
|
||||
try FileManager.default.createDirectory(at: folderURL, withIntermediateDirectories: true)
|
||||
defer {
|
||||
try? FileManager.default.removeItem(at: folderURL)
|
||||
}
|
||||
|
||||
let database = SyncDatabase(databasePath: folderURL.appendingPathComponent("Sync.sqlite3").path)
|
||||
let articleIDs = (0..<10).map { "article-\($0)" }
|
||||
await database.insertStatuses(Set(articleIDs.map { SyncStatus(articleID: $0, key: .read, flag: true) }))
|
||||
|
||||
// Every call fails once the folder is gone, but the statements still prepare
|
||||
// cleanly — the failure only shows up while stepping through the rows.
|
||||
try FileManager.default.removeItem(at: folderURL)
|
||||
|
||||
#expect(await database.selectForProcessing() == nil)
|
||||
#expect(await database.selectPendingReadStatusArticleIDs() == nil)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user