Skip to content

Commit

Permalink
Merge pull request #755 from AndrewSB/andrew/store-and-load-fail
Browse files Browse the repository at this point in the history
ThreadSafetyTests: add failing test where we load and store an image
  • Loading branch information
kean authored Mar 3, 2024
2 parents 8ecbfc8 + 7dac32b commit 3b4c97f
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Tests/NukeThreadSafetyTests/ThreadSafetyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,32 @@ class ThreadSafetyTests: XCTestCase {
}
queue.waitUntilAllOperationsAreFinished()
}

func testDataCacheMultipleThreadAccess() {
let aURL = URL(string: "https://example.com/image-01-small.jpeg")!
let imageData = Test.data(name: "fixture", extension: "jpeg")

let expectSuccessFromCache = self.expectation(description: "one successful load, from cache")
expectSuccessFromCache.expectedFulfillmentCount = 1
expectSuccessFromCache.assertForOverFulfill = true

let pipeline = ImagePipeline(configuration: .withDataCache)
pipeline.cache.storeCachedData(imageData, for: ImageRequest.init(url: aURL))
pipeline.loadImage(with: aURL) { result in
switch result {
case .success(let response):
if response.cacheType == .memory || response.cacheType == .disk {
expectSuccessFromCache.fulfill()
} else {
XCTFail("didn't load that just cached image data: \(response)")
}
case .failure:
XCTFail("didn't load that just cached image data")
}
}

wait(for: [expectSuccessFromCache], timeout: 2)
}
}

final class OperationThreadSafetyTests: XCTestCase {
Expand Down

0 comments on commit 3b4c97f

Please sign in to comment.