now with notifications
This commit is contained in:
@@ -289,6 +289,26 @@ final class MockProtocol: URLProtocol, @unchecked Sendable {
|
||||
check(completionFixture.complete, "Full measured progress is completed")
|
||||
completionFixture.progress = 0.9999
|
||||
check(!completionFixture.complete, "Rounded near-100-percent progress is not completed")
|
||||
var notificationTracker = DownloadNotificationTracker()
|
||||
var eventTorrent = queue[0]
|
||||
eventTorrent.state = "queuedDL"; eventTorrent.progress = 0
|
||||
check(notificationTracker.observe([eventTorrent]).isEmpty, "Initial notification snapshot is silent")
|
||||
eventTorrent.state = "metaDL"
|
||||
check(notificationTracker.observe([eventTorrent]).isEmpty, "Metadata lookup does not notify download start")
|
||||
eventTorrent.state = "downloading"
|
||||
check(notificationTracker.observe([eventTorrent]).map(\.type) == [.started], "Queued torrent entering downloading emits a start event")
|
||||
check(notificationTracker.observe([eventTorrent]).isEmpty, "Unchanged polling never repeats start notifications")
|
||||
eventTorrent.state = "pausedDL"
|
||||
check(notificationTracker.observe([eventTorrent]).isEmpty, "Pausing emits no download notification")
|
||||
eventTorrent.state = "forcedDL"
|
||||
check(notificationTracker.observe([eventTorrent]).map(\.type) == [.started], "Resuming emits a new start event")
|
||||
eventTorrent.progress = 1; eventTorrent.state = "uploading"
|
||||
check(notificationTracker.observe([eventTorrent]).map(\.type) == [.completed], "Completion emits only a completion event")
|
||||
check(notificationTracker.observe([eventTorrent]).isEmpty, "Unchanged completion does not repeat")
|
||||
var reconnectTracker = DownloadNotificationTracker()
|
||||
check(reconnectTracker.observe([eventTorrent]).isEmpty, "Reconnect does not alert existing completed torrents")
|
||||
eventTorrent.hash = "new-download"; eventTorrent.progress = 0; eventTorrent.state = "downloading"
|
||||
check(reconnectTracker.observe([eventTorrent]).map(\.type) == [.started], "Newly added active download alerts after baseline")
|
||||
another.close(); transport.close(); print("\(checks) contract checks passed.")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user