Skip to content

Commit

Permalink
fix: Remove fetch test race by awaiting the expectations in order
Browse files Browse the repository at this point in the history
This prevents the fetch and fetch from cache test steps to execute concurrently.
  • Loading branch information
bobergj committed Aug 29, 2023
1 parent 47eb613 commit 2345e48
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Tests/NMAImageFetchTests/NMAImageFetchTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ final class NMAImageFetchTests: XCTestCase {
XCTFail()
}
}
wait(for: [expectationWithoutCaching], timeout: 5)
let expectationWithCaching = expectation(description: "Image request finished width caching")
_ = imageFetch.requestImage(imageFetchRequest) { result in
expectationWithCaching.fulfill()
Expand All @@ -35,7 +36,7 @@ final class NMAImageFetchTests: XCTestCase {
XCTFail()
}
}
waitForExpectations(timeout: 5)
wait(for: [expectationWithCaching], timeout: 5)
}

func testVectorLoading() throws {
Expand All @@ -54,6 +55,7 @@ final class NMAImageFetchTests: XCTestCase {
XCTFail()
}
}
wait(for: [expectationWithoutCaching], timeout: 5)
let expectationWithCaching = expectation(description: "Image request finished with caching")
_ = imageFetch.requestImage(imageFetchRequest) { result in
expectationWithCaching.fulfill()
Expand All @@ -64,7 +66,7 @@ final class NMAImageFetchTests: XCTestCase {
XCTFail()
}
}
waitForExpectations(timeout: 5)
wait(for: [expectationWithCaching], timeout: 5)
}

func testCancel() {
Expand Down

0 comments on commit 2345e48

Please sign in to comment.