Merge pull request #1373 from kielgillard/master

Fixes race conditions in FeedlyOperation progress reporting unit tests.
This commit is contained in:
Maurice Parker 2019-11-29 13:24:11 -06:00 committed by GitHub
commit 5373be508a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 0 deletions

View File

@ -147,6 +147,11 @@ class FeedlyOperationTests: XCTestCase {
func testProgressReporting() { func testProgressReporting() {
let progress = DownloadProgress(numberOfTasks: 0) let progress = DownloadProgress(numberOfTasks: 0)
let didChangeExpectation = expectation(forNotification: .DownloadProgressDidChange, object: progress)
// This number is the number of times breakpoints on calls to DownloadProgress.postDidChangeNotification is hit.
didChangeExpectation.expectedFulfillmentCount = 4
didChangeExpectation.assertForOverFulfill = true
let testOperation = TestOperation() let testOperation = TestOperation()
testOperation.downloadProgress = progress testOperation.downloadProgress = progress
@ -154,10 +159,17 @@ class FeedlyOperationTests: XCTestCase {
testOperation.downloadProgress = nil testOperation.downloadProgress = nil
XCTAssertTrue(progress.numberRemaining == 0) XCTAssertTrue(progress.numberRemaining == 0)
waitForExpectations(timeout: 2)
} }
func testProgressReportingOnCancel() { func testProgressReportingOnCancel() {
let progress = DownloadProgress(numberOfTasks: 0) let progress = DownloadProgress(numberOfTasks: 0)
let didChangeExpectation = expectation(forNotification: .DownloadProgressDidChange, object: progress)
// This number is the number of times breakpoints on calls to DownloadProgress.postDidChangeNotification is hit.
didChangeExpectation.expectedFulfillmentCount = 4
didChangeExpectation.assertForOverFulfill = true
let testOperation = TestOperation() let testOperation = TestOperation()
testOperation.downloadProgress = progress testOperation.downloadProgress = progress
@ -179,6 +191,11 @@ class FeedlyOperationTests: XCTestCase {
func testDoesProgressReportingOnSuccess() { func testDoesProgressReportingOnSuccess() {
let progress = DownloadProgress(numberOfTasks: 0) let progress = DownloadProgress(numberOfTasks: 0)
let didChangeExpectation = expectation(forNotification: .DownloadProgressDidChange, object: progress)
// This number is the number of times breakpoints on calls to DownloadProgress.postDidChangeNotification is hit.
didChangeExpectation.expectedFulfillmentCount = 4
didChangeExpectation.assertForOverFulfill = true
let testOperation = TestOperation() let testOperation = TestOperation()
testOperation.downloadProgress = progress testOperation.downloadProgress = progress
@ -198,6 +215,11 @@ class FeedlyOperationTests: XCTestCase {
func testProgressReportingOnFailure() { func testProgressReportingOnFailure() {
let progress = DownloadProgress(numberOfTasks: 0) let progress = DownloadProgress(numberOfTasks: 0)
let didChangeExpectation = expectation(forNotification: .DownloadProgressDidChange, object: progress)
// This number is the number of times breakpoints on calls to DownloadProgress.postDidChangeNotification is hit.
didChangeExpectation.expectedFulfillmentCount = 4
didChangeExpectation.assertForOverFulfill = true
let testOperation = TestOperation() let testOperation = TestOperation()
testOperation.mockError = TestOperationError.mockError testOperation.mockError = TestOperationError.mockError
testOperation.downloadProgress = progress testOperation.downloadProgress = progress