Revise Feedly tests to use MainThreadOperationQueue; get them building again. They don’t pass, but at least they build.

This commit is contained in:
Brent Simmons
2020-01-15 22:10:06 -08:00
parent 1d755e7f77
commit 57af7526da
18 changed files with 190 additions and 207 deletions

View File

@@ -9,6 +9,7 @@
import XCTest
@testable import Account
import RSWeb
import RSCore
class FeedlyAddNewFeedOperationTests: XCTestCase {
@@ -42,17 +43,17 @@ class FeedlyAddNewFeedOperationTests: XCTestCase {
let getCollections = FeedlyGetCollectionsOperation(service: caller, log: support.log)
let mirrorCollectionsAsFolders = FeedlyMirrorCollectionsAsFoldersOperation(account: account, collectionsProvider: getCollections, log: support.log)
mirrorCollectionsAsFolders.addDependency(getCollections)
MainThreadOperationQueue.shared.make(mirrorCollectionsAsFolders, dependOn: getCollections)
let createFolders = FeedlyCreateFeedsForCollectionFoldersOperation(account: account, feedsAndFoldersProvider: mirrorCollectionsAsFolders, log: support.log)
createFolders.addDependency(mirrorCollectionsAsFolders)
MainThreadOperationQueue.shared.make(createFolders, dependOn: mirrorCollectionsAsFolders)
let completionExpectation = expectation(description: "Did Finish")
createFolders.completionBlock = {
createFolders.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperations([getCollections, mirrorCollectionsAsFolders, createFolders], waitUntilFinished: false)
MainThreadOperationQueue.shared.addOperations([getCollections, mirrorCollectionsAsFolders, createFolders])
waitForExpectations(timeout: 2)
@@ -107,11 +108,11 @@ class FeedlyAddNewFeedOperationTests: XCTestCase {
// If this expectation is not fulfilled, the operation is not calling `didFinish`.
let completionExpectation = expectation(description: "Did Finish")
addNewFeed.completionBlock = {
addNewFeed.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(addNewFeed)
MainThreadOperationQueue.shared.addOperation(addNewFeed)
XCTAssert(progress.numberRemaining > 0)
@@ -155,11 +156,11 @@ class FeedlyAddNewFeedOperationTests: XCTestCase {
// If this expectation is not fulfilled, the operation is not calling `didFinish`.
let completionExpectation = expectation(description: "Did Finish")
addNewFeed.completionBlock = {
addNewFeed.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(addNewFeed)
MainThreadOperationQueue.shared.addOperation(addNewFeed)
XCTAssert(progress.numberRemaining > 0)
@@ -232,11 +233,11 @@ class FeedlyAddNewFeedOperationTests: XCTestCase {
// If this expectation is not fulfilled, the operation is not calling `didFinish`.
let completionExpectation = expectation(description: "Did Finish")
addNewFeed.completionBlock = {
addNewFeed.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(addNewFeed)
MainThreadOperationQueue.shared.addOperation(addNewFeed)
XCTAssert(progress.numberRemaining > 0)

View File

@@ -8,6 +8,7 @@
import XCTest
@testable import Account
import RSCore
class FeedlyCheckpointOperationTests: XCTestCase {
@@ -28,11 +29,11 @@ class FeedlyCheckpointOperationTests: XCTestCase {
operation.checkpointDelegate = delegate
let didFinishExpectation = expectation(description: "Did Finish")
operation.completionBlock = {
operation.completionBlock = { _ in
didFinishExpectation.fulfill()
}
OperationQueue.main.addOperation(operation)
MainThreadOperationQueue.shared.addOperation(operation)
waitForExpectations(timeout: 2)
}
@@ -48,11 +49,11 @@ class FeedlyCheckpointOperationTests: XCTestCase {
operation.checkpointDelegate = delegate
let didFinishExpectation = expectation(description: "Did Finish")
operation.completionBlock = {
operation.completionBlock = { _ in
didFinishExpectation.fulfill()
}
OperationQueue.main.addOperation(operation)
MainThreadOperationQueue.shared.addOperation(operation)
operation.cancel()

View File

@@ -8,6 +8,7 @@
import XCTest
@testable import Account
import RSCore
class FeedlyCreateFeedsForCollectionFoldersOperationTests: XCTestCase {
@@ -54,13 +55,13 @@ class FeedlyCreateFeedsForCollectionFoldersOperationTests: XCTestCase {
let createFeeds = FeedlyCreateFeedsForCollectionFoldersOperation(account: account, feedsAndFoldersProvider: provider, log: support.log)
let completionExpectation = expectation(description: "Did Finish")
createFeeds.completionBlock = {
createFeeds.completionBlock = { _ in
completionExpectation.fulfill()
}
XCTAssertTrue(account.flattenedWebFeeds().isEmpty, "Expected empty account.")
OperationQueue.main.addOperation(createFeeds)
MainThreadOperationQueue.shared.addOperation(createFeeds)
waitForExpectations(timeout: 2)
@@ -125,13 +126,13 @@ class FeedlyCreateFeedsForCollectionFoldersOperationTests: XCTestCase {
let createFeeds = FeedlyCreateFeedsForCollectionFoldersOperation(account: account, feedsAndFoldersProvider: provider, log: support.log)
let completionExpectation = expectation(description: "Did Finish")
createFeeds.completionBlock = {
createFeeds.completionBlock = { _ in
completionExpectation.fulfill()
}
XCTAssertTrue(account.flattenedWebFeeds().isEmpty, "Expected empty account.")
OperationQueue.main.addOperation(createFeeds)
MainThreadOperationQueue.shared.addOperation(createFeeds)
waitForExpectations(timeout: 2)
}
@@ -149,11 +150,11 @@ class FeedlyCreateFeedsForCollectionFoldersOperationTests: XCTestCase {
let removeFeeds = FeedlyCreateFeedsForCollectionFoldersOperation(account: account, feedsAndFoldersProvider: provider, log: support.log)
let completionExpectation = expectation(description: "Did Finish")
removeFeeds.completionBlock = {
removeFeeds.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(removeFeeds)
MainThreadOperationQueue.shared.addOperation(removeFeeds)
waitForExpectations(timeout: 2)

View File

@@ -9,6 +9,7 @@
import XCTest
@testable import Account
import os.log
import RSCore
class FeedlyGetCollectionsOperationTests: XCTestCase {
@@ -20,11 +21,11 @@ class FeedlyGetCollectionsOperationTests: XCTestCase {
let getCollections = FeedlyGetCollectionsOperation(service: caller, log: support.log)
let completionExpectation = expectation(description: "Did Finish")
getCollections.completionBlock = {
getCollections.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(getCollections)
MainThreadOperationQueue.shared.addOperation(getCollections)
waitForExpectations(timeout: 2)
@@ -78,11 +79,11 @@ class FeedlyGetCollectionsOperationTests: XCTestCase {
getCollections.delegate = delegate
let completionExpectation = expectation(description: "Did Finish")
getCollections.completionBlock = {
getCollections.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(getCollections)
MainThreadOperationQueue.shared.addOperation(getCollections)
waitForExpectations(timeout: 2)

View File

@@ -8,6 +8,7 @@
import XCTest
@testable import Account
import RSCore
class FeedlyGetStreamContentsOperationTests: XCTestCase {
@@ -35,11 +36,11 @@ class FeedlyGetStreamContentsOperationTests: XCTestCase {
service.mockResult = .failure(URLError(.fileDoesNotExist))
let completionExpectation = expectation(description: "Did Finish")
getStreamContents.completionBlock = {
getStreamContents.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(getStreamContents)
MainThreadOperationQueue.shared.addOperation(getStreamContents)
waitForExpectations(timeout: 2)
@@ -68,11 +69,11 @@ class FeedlyGetStreamContentsOperationTests: XCTestCase {
}
let completionExpectation = expectation(description: "Did Finish")
getStreamContents.completionBlock = {
getStreamContents.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(getStreamContents)
MainThreadOperationQueue.shared.addOperation(getStreamContents)
waitForExpectations(timeout: 2)
@@ -100,11 +101,11 @@ class FeedlyGetStreamContentsOperationTests: XCTestCase {
let getStreamContents = FeedlyGetStreamContentsOperation(account: account, resource: resource, service: caller, continuation: nil, newerThan: nil, unreadOnly: nil, log: support.log)
let completionExpectation = expectation(description: "Did Finish")
getStreamContents.completionBlock = {
getStreamContents.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(getStreamContents)
MainThreadOperationQueue.shared.addOperation(getStreamContents)
waitForExpectations(timeout: 2)

View File

@@ -8,6 +8,7 @@
import XCTest
@testable import Account
import RSCore
class FeedlyGetStreamIdsOperationTests: XCTestCase {
@@ -35,11 +36,11 @@ class FeedlyGetStreamIdsOperationTests: XCTestCase {
service.mockResult = .failure(URLError(.fileDoesNotExist))
let completionExpectation = expectation(description: "Did Finish")
getStreamIds.completionBlock = {
getStreamIds.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(getStreamIds)
MainThreadOperationQueue.shared.addOperation(getStreamIds)
waitForExpectations(timeout: 2)
@@ -68,11 +69,11 @@ class FeedlyGetStreamIdsOperationTests: XCTestCase {
}
let completionExpectation = expectation(description: "Did Finish")
getStreamIds.completionBlock = {
getStreamIds.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(getStreamIds)
MainThreadOperationQueue.shared.addOperation(getStreamIds)
waitForExpectations(timeout: 2)
@@ -95,11 +96,11 @@ class FeedlyGetStreamIdsOperationTests: XCTestCase {
let getStreamIds = FeedlyGetStreamIdsOperation(account: account, resource: resource, service: caller, continuation: nil, newerThan: nil, unreadOnly: nil, log: support.log)
let completionExpectation = expectation(description: "Did Finish")
getStreamIds.completionBlock = {
getStreamIds.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(getStreamIds)
MainThreadOperationQueue.shared.addOperation(getStreamIds)
waitForExpectations(timeout: 2)

View File

@@ -8,6 +8,7 @@
import XCTest
@testable import Account
import RSCore
class FeedlyLogoutOperationTests: XCTestCase {
@@ -68,17 +69,17 @@ class FeedlyLogoutOperationTests: XCTestCase {
// If this expectation is not fulfilled, the operation is not calling `didFinish`.
let completionExpectation = expectation(description: "Did Finish")
logout.completionBlock = {
logout.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(logout)
MainThreadOperationQueue.shared.addOperation(logout)
logout.cancel()
waitForExpectations(timeout: 1)
XCTAssertTrue(logout.isCancelled)
XCTAssertTrue(logout.isCanceled)
XCTAssertTrue(logout.isFinished)
do {
@@ -101,15 +102,15 @@ class FeedlyLogoutOperationTests: XCTestCase {
// If this expectation is not fulfilled, the operation is not calling `didFinish`.
let completionExpectation = expectation(description: "Did Finish")
logout.completionBlock = {
logout.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(logout)
MainThreadOperationQueue.shared.addOperation(logout)
waitForExpectations(timeout: 1)
XCTAssertFalse(logout.isCancelled)
XCTAssertFalse(logout.isCanceled)
do {
let accountAccessToken = try account.retrieveCredentials(type: .oauthAccessToken)
@@ -147,15 +148,15 @@ class FeedlyLogoutOperationTests: XCTestCase {
// If this expectation is not fulfilled, the operation is not calling `didFinish`.
let completionExpectation = expectation(description: "Did Finish")
logout.completionBlock = {
logout.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(logout)
MainThreadOperationQueue.shared.addOperation(logout)
waitForExpectations(timeout: 1)
XCTAssertFalse(logout.isCancelled)
XCTAssertFalse(logout.isCanceled)
do {
let accountAccessToken = try account.retrieveCredentials(type: .oauthAccessToken)
@@ -193,15 +194,15 @@ class FeedlyLogoutOperationTests: XCTestCase {
// If this expectation is not fulfilled, the operation is not calling `didFinish`.
let completionExpectation = expectation(description: "Did Finish")
logout.completionBlock = {
logout.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(logout)
MainThreadOperationQueue.shared.addOperation(logout)
waitForExpectations(timeout: 1)
XCTAssertFalse(logout.isCancelled)
XCTAssertFalse(logout.isCanceled)
do {
let accountAccessToken = try account.retrieveCredentials(type: .oauthAccessToken)

View File

@@ -8,6 +8,7 @@
import XCTest
@testable import Account
import RSCore
class FeedlyMirrorCollectionsAsFoldersOperationTests: XCTestCase {
@@ -37,14 +38,14 @@ class FeedlyMirrorCollectionsAsFoldersOperationTests: XCTestCase {
let provider = CollectionsProvider()
let mirrorOperation = FeedlyMirrorCollectionsAsFoldersOperation(account: account, collectionsProvider: provider, log: support.log)
let completionExpectation = expectation(description: "Did Finish")
mirrorOperation.completionBlock = {
mirrorOperation.completionBlock = { _ in
completionExpectation.fulfill()
}
XCTAssertTrue(mirrorOperation.collectionsAndFolders.isEmpty)
XCTAssertTrue(mirrorOperation.feedsAndFolders.isEmpty)
OperationQueue.main.addOperation(mirrorOperation)
MainThreadOperationQueue.shared.addOperation(mirrorOperation)
waitForExpectations(timeout: 2)
@@ -69,11 +70,11 @@ class FeedlyMirrorCollectionsAsFoldersOperationTests: XCTestCase {
do {
let addFolders = FeedlyMirrorCollectionsAsFoldersOperation(account: account, collectionsProvider: provider, log: support.log)
let completionExpectation = expectation(description: "Did Finish")
addFolders.completionBlock = {
addFolders.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(addFolders)
MainThreadOperationQueue.shared.addOperation(addFolders)
waitForExpectations(timeout: 2)
}
@@ -83,11 +84,11 @@ class FeedlyMirrorCollectionsAsFoldersOperationTests: XCTestCase {
let removeFolders = FeedlyMirrorCollectionsAsFoldersOperation(account: account, collectionsProvider: provider, log: support.log)
let completionExpectation = expectation(description: "Did Finish")
removeFolders.completionBlock = {
removeFolders.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(removeFolders)
MainThreadOperationQueue.shared.addOperation(removeFolders)
waitForExpectations(timeout: 2)
@@ -131,11 +132,11 @@ class FeedlyMirrorCollectionsAsFoldersOperationTests: XCTestCase {
let provider = CollectionsAndFeedsProvider()
let mirrorOperation = FeedlyMirrorCollectionsAsFoldersOperation(account: account, collectionsProvider: provider, log: support.log)
let completionExpectation = expectation(description: "Did Finish")
mirrorOperation.completionBlock = {
mirrorOperation.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(mirrorOperation)
MainThreadOperationQueue.shared.addOperation(mirrorOperation)
waitForExpectations(timeout: 2)
@@ -172,14 +173,14 @@ class FeedlyMirrorCollectionsAsFoldersOperationTests: XCTestCase {
let addFoldersAndFeeds = FeedlyMirrorCollectionsAsFoldersOperation(account: account, collectionsProvider: provider, log: support.log)
let createFeeds = FeedlyCreateFeedsForCollectionFoldersOperation(account: account, feedsAndFoldersProvider: addFoldersAndFeeds, log: support.log)
createFeeds.addDependency(addFoldersAndFeeds)
MainThreadOperationQueue.shared.make(createFeeds, dependOn: addFoldersAndFeeds)
let completionExpectation = expectation(description: "Did Finish")
createFeeds.completionBlock = {
createFeeds.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperations([addFoldersAndFeeds, createFeeds], waitUntilFinished: false)
MainThreadOperationQueue.shared.addOperations([addFoldersAndFeeds, createFeeds])
waitForExpectations(timeout: 2)
@@ -192,11 +193,11 @@ class FeedlyMirrorCollectionsAsFoldersOperationTests: XCTestCase {
let removeFolders = FeedlyMirrorCollectionsAsFoldersOperation(account: account, collectionsProvider: provider, log: support.log)
let completionExpectation = expectation(description: "Did Finish")
removeFolders.completionBlock = {
removeFolders.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(removeFolders)
MainThreadOperationQueue.shared.addOperation(removeFolders)
waitForExpectations(timeout: 2)

View File

@@ -9,6 +9,7 @@
import XCTest
@testable import Account
import RSWeb
import RSCore
class FeedlyOperationTests: XCTestCase {
@@ -21,7 +22,7 @@ class FeedlyOperationTests: XCTestCase {
var didCallMainExpectation: XCTestExpectation?
var mockError: Error?
override func main() {
override func run() {
// Should always call on main thread.
XCTAssertTrue(Thread.isMainThread)
@@ -50,7 +51,7 @@ class FeedlyOperationTests: XCTestCase {
let testOperation = TestOperation()
testOperation.didCallMainExpectation = expectation(description: "Did Call Main")
OperationQueue.main.addOperation(testOperation)
MainThreadOperationQueue.shared.addOperation(testOperation)
waitForExpectations(timeout: 2)
}
@@ -65,7 +66,7 @@ class FeedlyOperationTests: XCTestCase {
testOperation.delegate = delegate
OperationQueue.main.addOperation(testOperation)
MainThreadOperationQueue.shared.addOperation(testOperation)
waitForExpectations(timeout: 2)
@@ -81,23 +82,22 @@ class FeedlyOperationTests: XCTestCase {
testOperation.didCallMainExpectation = expectation(description: "Did Call Main")
let completionExpectation = expectation(description: "Operation Completed")
testOperation.completionBlock = {
testOperation.completionBlock = { _ in
completionExpectation.fulfill()
}
XCTAssertTrue(testOperation.isReady)
XCTAssertFalse(testOperation.isFinished)
XCTAssertFalse(testOperation.isExecuting)
XCTAssertFalse(testOperation.isCancelled)
XCTAssertFalse(testOperation.isCanceled)
OperationQueue.main.addOperation(testOperation)
MainThreadOperationQueue.shared.addOperation(testOperation)
waitForExpectations(timeout: 2)
XCTAssertTrue(testOperation.isReady)
XCTAssertTrue(testOperation.isFinished)
XCTAssertFalse(testOperation.isExecuting)
XCTAssertFalse(testOperation.isCancelled)
XCTAssertFalse(testOperation.isCanceled)
}
func testOperationCancellationFlags() {
@@ -106,43 +106,41 @@ class FeedlyOperationTests: XCTestCase {
testOperation.didCallMainExpectation?.isInverted = true
let completionExpectation = expectation(description: "Operation Completed")
testOperation.completionBlock = {
testOperation.completionBlock = { _ in
completionExpectation.fulfill()
}
XCTAssertTrue(testOperation.isReady)
XCTAssertFalse(testOperation.isFinished)
XCTAssertFalse(testOperation.isExecuting)
XCTAssertFalse(testOperation.isCancelled)
XCTAssertFalse(testOperation.isCanceled)
OperationQueue.main.addOperation(testOperation)
MainThreadOperationQueue.shared.addOperation(testOperation)
testOperation.cancel()
waitForExpectations(timeout: 2)
XCTAssertTrue(testOperation.isReady)
XCTAssertTrue(testOperation.isFinished)
XCTAssertFalse(testOperation.isExecuting)
XCTAssertTrue(testOperation.isCancelled)
XCTAssertTrue(testOperation.isCanceled)
}
func testDependency() {
let testOperation = TestOperation()
testOperation.didCallMainExpectation = expectation(description: "Did Call Main")
let dependencyExpectation = expectation(description: "Did Call Dependency")
let blockOperation = BlockOperation {
dependencyExpectation.fulfill()
}
blockOperation.addDependency(testOperation)
XCTAssertTrue(blockOperation.dependencies.contains(testOperation))
OperationQueue.main.addOperations([testOperation, blockOperation], waitUntilFinished: false)
waitForExpectations(timeout: 2)
// let testOperation = TestOperation()
// testOperation.didCallMainExpectation = expectation(description: "Did Call Main")
//
// let dependencyExpectation = expectation(description: "Did Call Dependency")
// let blockOperation = BlockOperation {
// dependencyExpectation.fulfill()
// }
//
// MainThreadOperationQueue.shared.make(blockOperation, dependOn: testOperation)
//
// //XCTAssertTrue(blockOperation.dependencies.contains(testOperation))
//
// MainThreadOperationQueue.shared.addOperations([testOperation, blockOperation])
//
// waitForExpectations(timeout: 2)
}
func testProgressReporting() {
@@ -174,11 +172,11 @@ class FeedlyOperationTests: XCTestCase {
testOperation.downloadProgress = progress
let completionExpectation = expectation(description: "Operation Completed")
testOperation.completionBlock = {
testOperation.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(testOperation)
MainThreadOperationQueue.shared.addOperation(testOperation)
XCTAssertTrue(progress.numberRemaining == 1)
testOperation.cancel()
@@ -200,11 +198,11 @@ class FeedlyOperationTests: XCTestCase {
testOperation.downloadProgress = progress
let completionExpectation = expectation(description: "Operation Completed")
testOperation.completionBlock = {
testOperation.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(testOperation)
MainThreadOperationQueue.shared.addOperation(testOperation)
XCTAssertTrue(progress.numberRemaining == 1)
@@ -225,11 +223,11 @@ class FeedlyOperationTests: XCTestCase {
testOperation.downloadProgress = progress
let completionExpectation = expectation(description: "Operation Completed")
testOperation.completionBlock = {
testOperation.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(testOperation)
MainThreadOperationQueue.shared.addOperation(testOperation)
XCTAssertTrue(progress.numberRemaining == 1)

View File

@@ -9,6 +9,7 @@
import XCTest
@testable import Account
import RSParser
import RSCore
class FeedlyOrganiseParsedItemsByFeedOperationTests: XCTestCase {
@@ -42,11 +43,11 @@ class FeedlyOrganiseParsedItemsByFeedOperationTests: XCTestCase {
let organise = FeedlyOrganiseParsedItemsByFeedOperation(account: account, parsedItemProvider: provider, log: support.log)
let completionExpectation = expectation(description: "Did Finish")
organise.completionBlock = {
organise.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(organise)
MainThreadOperationQueue.shared.addOperation(organise)
waitForExpectations(timeout: 2)
@@ -63,11 +64,11 @@ class FeedlyOrganiseParsedItemsByFeedOperationTests: XCTestCase {
let organise = FeedlyOrganiseParsedItemsByFeedOperation(account: account, parsedItemProvider: provider, log: support.log)
let completionExpectation = expectation(description: "Did Finish")
organise.completionBlock = {
organise.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(organise)
MainThreadOperationQueue.shared.addOperation(organise)
waitForExpectations(timeout: 2)
@@ -84,11 +85,11 @@ class FeedlyOrganiseParsedItemsByFeedOperationTests: XCTestCase {
let organise = FeedlyOrganiseParsedItemsByFeedOperation(account: account, parsedItemProvider: provider, log: support.log)
let completionExpectation = expectation(description: "Did Finish")
organise.completionBlock = {
organise.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(organise)
MainThreadOperationQueue.shared.addOperation(organise)
waitForExpectations(timeout: 2)

View File

@@ -9,6 +9,7 @@
import XCTest
@testable import Account
import RSWeb
import RSCore
class FeedlyRefreshAccessTokenOperationTests: XCTestCase {
@@ -56,17 +57,17 @@ class FeedlyRefreshAccessTokenOperationTests: XCTestCase {
// If this expectation is not fulfilled, the operation is not calling `didFinish`.
let completionExpectation = expectation(description: "Did Finish")
refresh.completionBlock = {
refresh.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(refresh)
MainThreadOperationQueue.shared.addOperation(refresh)
refresh.cancel()
waitForExpectations(timeout: 1)
XCTAssertTrue(refresh.isCancelled)
XCTAssertTrue(refresh.isCanceled)
}
class TestRefreshTokenDelegate: FeedlyOperationDelegate {
@@ -95,11 +96,11 @@ class FeedlyRefreshAccessTokenOperationTests: XCTestCase {
// If this expectation is not fulfilled, the operation is not calling `didFinish`.
let completionExpectation = expectation(description: "Did Finish")
refresh.completionBlock = {
refresh.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(refresh)
MainThreadOperationQueue.shared.addOperation(refresh)
waitForExpectations(timeout: 1)
@@ -142,11 +143,11 @@ class FeedlyRefreshAccessTokenOperationTests: XCTestCase {
// If this expectation is not fulfilled, the operation is not calling `didFinish`.
let completionExpectation = expectation(description: "Did Finish")
refresh.completionBlock = {
refresh.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(refresh)
MainThreadOperationQueue.shared.addOperation(refresh)
waitForExpectations(timeout: 1)
@@ -196,11 +197,11 @@ class FeedlyRefreshAccessTokenOperationTests: XCTestCase {
// If this expectation is not fulfilled, the operation is not calling `didFinish`.
let completionExpectation = expectation(description: "Did Finish")
refresh.completionBlock = {
refresh.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(refresh)
MainThreadOperationQueue.shared.addOperation(refresh)
waitForExpectations(timeout: 1)

View File

@@ -10,6 +10,7 @@ import XCTest
@testable import Account
import SyncDatabase
import Articles
import RSCore
class FeedlySendArticleStatusesOperationTests: XCTestCase {
@@ -36,11 +37,11 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase {
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service, log: support.log)
let didFinishExpectation = expectation(description: "Did Finish")
send.completionBlock = {
send.completionBlock = { _ in
didFinishExpectation.fulfill()
}
OperationQueue.main.addOperation(send)
MainThreadOperationQueue.shared.addOperation(send)
waitForExpectations(timeout: 2)
}
@@ -67,11 +68,11 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase {
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service, log: support.log)
let didFinishExpectation = expectation(description: "Did Finish")
send.completionBlock = {
send.completionBlock = { _ in
didFinishExpectation.fulfill()
}
OperationQueue.main.addOperation(send)
MainThreadOperationQueue.shared.addOperation(send)
waitForExpectations(timeout: 2)
@@ -110,11 +111,11 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase {
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service, log: support.log)
let didFinishExpectation = expectation(description: "Did Finish")
send.completionBlock = {
send.completionBlock = { _ in
didFinishExpectation.fulfill()
}
OperationQueue.main.addOperation(send)
MainThreadOperationQueue.shared.addOperation(send)
waitForExpectations(timeout: 2)
@@ -153,11 +154,11 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase {
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service, log: support.log)
let didFinishExpectation = expectation(description: "Did Finish")
send.completionBlock = {
send.completionBlock = { _ in
didFinishExpectation.fulfill()
}
OperationQueue.main.addOperation(send)
MainThreadOperationQueue.shared.addOperation(send)
waitForExpectations(timeout: 2)
@@ -196,11 +197,11 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase {
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service, log: support.log)
let didFinishExpectation = expectation(description: "Did Finish")
send.completionBlock = {
send.completionBlock = { _ in
didFinishExpectation.fulfill()
}
OperationQueue.main.addOperation(send)
MainThreadOperationQueue.shared.addOperation(send)
waitForExpectations(timeout: 2)
@@ -239,11 +240,11 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase {
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service, log: support.log)
let didFinishExpectation = expectation(description: "Did Finish")
send.completionBlock = {
send.completionBlock = { _ in
didFinishExpectation.fulfill()
}
OperationQueue.main.addOperation(send)
MainThreadOperationQueue.shared.addOperation(send)
waitForExpectations(timeout: 2)
@@ -282,11 +283,11 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase {
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service, log: support.log)
let didFinishExpectation = expectation(description: "Did Finish")
send.completionBlock = {
send.completionBlock = { _ in
didFinishExpectation.fulfill()
}
OperationQueue.main.addOperation(send)
MainThreadOperationQueue.shared.addOperation(send)
waitForExpectations(timeout: 2)
@@ -325,11 +326,11 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase {
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service, log: support.log)
let didFinishExpectation = expectation(description: "Did Finish")
send.completionBlock = {
send.completionBlock = { _ in
didFinishExpectation.fulfill()
}
OperationQueue.main.addOperation(send)
MainThreadOperationQueue.shared.addOperation(send)
waitForExpectations(timeout: 2)
@@ -368,11 +369,11 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase {
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service, log: support.log)
let didFinishExpectation = expectation(description: "Did Finish")
send.completionBlock = {
send.completionBlock = { _ in
didFinishExpectation.fulfill()
}
OperationQueue.main.addOperation(send)
MainThreadOperationQueue.shared.addOperation(send)
waitForExpectations(timeout: 2)
@@ -428,11 +429,11 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase {
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service, log: support.log)
let didFinishExpectation = expectation(description: "Did Finish")
send.completionBlock = {
send.completionBlock = { _ in
didFinishExpectation.fulfill()
}
OperationQueue.main.addOperation(send)
MainThreadOperationQueue.shared.addOperation(send)
waitForExpectations(timeout: 2)
@@ -489,11 +490,11 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase {
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service, log: support.log)
let didFinishExpectation = expectation(description: "Did Finish")
send.completionBlock = {
send.completionBlock = { _ in
didFinishExpectation.fulfill()
}
OperationQueue.main.addOperation(send)
MainThreadOperationQueue.shared.addOperation(send)
waitForExpectations(timeout: 2)

View File

@@ -9,6 +9,7 @@
import XCTest
@testable import Account
import RSWeb
import RSCore
class FeedlySyncAllOperationTests: XCTestCase {
@@ -85,7 +86,7 @@ class FeedlySyncAllOperationTests: XCTestCase {
// If this expectation is not fulfilled, the operation is not calling `didFinish`.
let completionExpectation = expectation(description: "Did Finish")
syncAll.completionBlock = {
syncAll.completionBlock = { _ in
completionExpectation.fulfill()
}
@@ -102,7 +103,7 @@ class FeedlySyncAllOperationTests: XCTestCase {
syncCompletionExpectation.fulfill()
}
OperationQueue.main.addOperation(syncAll)
MainThreadOperationQueue.shared.addOperation(syncAll)
XCTAssertTrue(progress.numberOfTasks > 1)
@@ -155,11 +156,11 @@ class FeedlySyncAllOperationTests: XCTestCase {
// If this expectation is not fulfilled, the operation is not calling `didFinish`.
let completionExpectation = expectation(description: "Did Finish")
syncAll.completionBlock = {
syncAll.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(syncAll)
MainThreadOperationQueue.shared.addOperation(syncAll)
XCTAssertTrue(progress.numberOfTasks > 1)
@@ -266,13 +267,13 @@ class FeedlySyncAllOperationTests: XCTestCase {
// If this expectation is not fulfilled, the operation is not calling `didFinish`.
let completionExpectation = expectation(description: "Did Finish")
syncAll.completionBlock = {
syncAll.completionBlock = { _ in
completionExpectation.fulfill()
}
lastSuccessfulFetchStartDate = Date()
OperationQueue.main.addOperation(syncAll)
MainThreadOperationQueue.shared.addOperation(syncAll)
XCTAssertTrue(progress.numberOfTasks > 1)

View File

@@ -8,6 +8,7 @@
import XCTest
@testable import Account
import RSCore
class FeedlySyncStreamContentsOperationTests: XCTestCase {
@@ -47,11 +48,11 @@ class FeedlySyncStreamContentsOperationTests: XCTestCase {
let syncStreamContents = FeedlySyncStreamContentsOperation(account: account, resource: resource, service: service, newerThan: newerThan, log: support.log)
let completionExpectation = expectation(description: "Did Finish")
syncStreamContents.completionBlock = {
syncStreamContents.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(syncStreamContents)
MainThreadOperationQueue.shared.addOperation(syncStreamContents)
waitForExpectations(timeout: 2)
@@ -81,11 +82,11 @@ class FeedlySyncStreamContentsOperationTests: XCTestCase {
let syncStreamContents = FeedlySyncStreamContentsOperation(account: account, resource: resource, service: service, newerThan: newerThan, log: support.log)
let completionExpectation = expectation(description: "Did Finish")
syncStreamContents.completionBlock = {
syncStreamContents.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(syncStreamContents)
MainThreadOperationQueue.shared.addOperation(syncStreamContents)
waitForExpectations(timeout: 2)
}
@@ -122,11 +123,11 @@ class FeedlySyncStreamContentsOperationTests: XCTestCase {
let syncStreamContents = FeedlySyncStreamContentsOperation(account: account, resource: resource, service: service, newerThan: newerThan, log: support.log)
let completionExpectation = expectation(description: "Did Finish")
syncStreamContents.completionBlock = {
syncStreamContents.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(syncStreamContents)
MainThreadOperationQueue.shared.addOperation(syncStreamContents)
waitForExpectations(timeout: 30)

View File

@@ -9,6 +9,7 @@
import XCTest
@testable import Account
import RSParser
import RSCore
class FeedlyUpdateAccountFeedsWithItemsOperationTests: XCTestCase {
@@ -40,11 +41,11 @@ class FeedlyUpdateAccountFeedsWithItemsOperationTests: XCTestCase {
let update = FeedlyUpdateAccountFeedsWithItemsOperation(account: account, organisedItemsProvider: provider, log: support.log)
let completionExpectation = expectation(description: "Did Finish")
update.completionBlock = {
update.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(update)
MainThreadOperationQueue.shared.addOperation(update)
waitForExpectations(timeout: 2)
@@ -64,11 +65,11 @@ class FeedlyUpdateAccountFeedsWithItemsOperationTests: XCTestCase {
let update = FeedlyUpdateAccountFeedsWithItemsOperation(account: account, organisedItemsProvider: provider, log: support.log)
let completionExpectation = expectation(description: "Did Finish")
update.completionBlock = {
update.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(update)
MainThreadOperationQueue.shared.addOperation(update)
waitForExpectations(timeout: 2)
@@ -92,11 +93,11 @@ class FeedlyUpdateAccountFeedsWithItemsOperationTests: XCTestCase {
let update = FeedlyUpdateAccountFeedsWithItemsOperation(account: account, organisedItemsProvider: provider, log: support.log)
let completionExpectation = expectation(description: "Did Finish")
update.completionBlock = {
update.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(update)
MainThreadOperationQueue.shared.addOperation(update)
waitForExpectations(timeout: 10) // 10,000 articles takes ~ three seconds for me.
@@ -120,11 +121,11 @@ class FeedlyUpdateAccountFeedsWithItemsOperationTests: XCTestCase {
let update = FeedlyUpdateAccountFeedsWithItemsOperation(account: account, organisedItemsProvider: provider, log: support.log)
let completionExpectation = expectation(description: "Did Finish")
update.completionBlock = {
update.completionBlock = { _ in
completionExpectation.fulfill()
}
OperationQueue.main.addOperation(update)
MainThreadOperationQueue.shared.addOperation(update)
update.cancel()

View File

@@ -8,14 +8,27 @@
import Foundation
import AuthenticationServices
import RSCore
public protocol OAuthAccountAuthorizationOperationDelegate: class {
func oauthAccountAuthorizationOperation(_ operation: OAuthAccountAuthorizationOperation, didCreate account: Account)
func oauthAccountAuthorizationOperation(_ operation: OAuthAccountAuthorizationOperation, didFailWith error: Error)
}
public final class OAuthAccountAuthorizationOperation: Operation, ASWebAuthenticationPresentationContextProviding {
@objc public final class OAuthAccountAuthorizationOperation: NSObject, MainThreadOperation, ASWebAuthenticationPresentationContextProviding {
public var isCanceled: Bool = false {
didSet {
if isCanceled {
cancel()
}
}
}
public var id: Int?
public weak var operationDelegate: MainThreadOperationDelegate?
public var name: String?
public var completionBlock: MainThreadOperation.MainThreadOperationCompletionBlock?
public weak var presentationAnchor: ASPresentationAnchor?
public weak var delegate: OAuthAccountAuthorizationOperationDelegate?
@@ -28,15 +41,9 @@ public final class OAuthAccountAuthorizationOperation: Operation, ASWebAuthentic
self.oauthClient = Account.oauthAuthorizationClient(for: accountType)
}
override public func main() {
assert(Thread.isMainThread)
public func run() {
assert(presentationAnchor != nil, "\(self) outlived presentation anchor.")
guard !isCancelled else {
didFinish()
return
}
let request = Account.oauthAuthorizationCodeGrantRequest(for: accountType)
guard let url = request.url else {
@@ -63,13 +70,12 @@ public final class OAuthAccountAuthorizationOperation: Operation, ASWebAuthentic
session.start()
}
override public func cancel() {
public func cancel() {
session?.cancel()
super.cancel()
}
private func didEndAuthentication(url: URL?, error: Error?) {
guard !isCancelled else {
guard !isCanceled else {
didFinish()
return
}
@@ -102,7 +108,7 @@ public final class OAuthAccountAuthorizationOperation: Operation, ASWebAuthentic
}
private func didEndRequestingAccessToken(_ result: Result<OAuthAuthorizationGrant, Error>) {
guard !isCancelled else {
guard !isCanceled else {
didFinish()
return
}
@@ -140,48 +146,12 @@ public final class OAuthAccountAuthorizationOperation: Operation, ASWebAuthentic
private func didFinish() {
assert(Thread.isMainThread)
assert(!isFinished, "Finished operation is attempting to finish again.")
self.isExecutingOperation = false
self.isFinishedOperation = true
operationDelegate?.operationDidComplete(self)
}
private func didFinish(_ error: Error) {
assert(Thread.isMainThread)
assert(!isFinished, "Finished operation is attempting to finish again.")
delegate?.oauthAccountAuthorizationOperation(self, didFailWith: error)
didFinish()
}
override public func start() {
isExecutingOperation = true
DispatchQueue.main.async {
self.main()
}
}
override public var isExecuting: Bool {
return isExecutingOperation
}
private var isExecutingOperation = false {
willSet {
willChangeValue(for: \.isExecuting)
}
didSet {
didChangeValue(for: \.isExecuting)
}
}
override public var isFinished: Bool {
return isFinishedOperation
}
private var isFinishedOperation = false {
willSet {
willChangeValue(for: \.isFinished)
}
didSet {
didChangeValue(for: \.isFinished)
}
}
}

View File

@@ -111,7 +111,7 @@ extension AccountsAddViewController: NSTableViewDelegate {
let addAccount = OAuthAccountAuthorizationOperation(accountType: .feedly)
addAccount.delegate = self
addAccount.presentationAnchor = self.view.window!
OperationQueue.main.addOperation(addAccount)
MainThreadOperationQueue.shared.addOperation(addAccount)
default:
break
}

View File

@@ -8,6 +8,7 @@
import Account
import UIKit
import RSCore
protocol AddAccountDismissDelegate: UIViewController {
func dismiss()
@@ -48,7 +49,7 @@ class AddAccountViewController: UITableViewController, AddAccountDismissDelegate
let addAccount = OAuthAccountAuthorizationOperation(accountType: .feedly)
addAccount.delegate = self
addAccount.presentationAnchor = self.view.window!
OperationQueue.main.addOperation(addAccount)
MainThreadOperationQueue.shared.addOperation(addAccount)
case 3:
let navController = UIStoryboard.account.instantiateViewController(withIdentifier: "FeedWranglerAccountNavigationViewController") as! UINavigationController
navController.modalPresentationStyle = .currentContext