Skip to content

Commit

Permalink
call fulfill inside the lock
Browse files Browse the repository at this point in the history
  • Loading branch information
azarovalex committed Jan 22, 2024
1 parent e9e3d0a commit 20dd048
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Tests/MapboxNavigationTests/ImageDownloaderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,22 @@ class ImageDownloaderTests: TestCase {

let concurrentOvercommitQueue = DispatchQueue(label: "queue", attributes: .concurrent)

let allImagesDownloaded = expectation(description: "All Images Downloaded")
allImagesDownloaded.expectedFulfillmentCount = imageUrls.count
var counter = Int()

let lock: NSLock = .init()
var downloadedImages: [URL: UIImage?] = .init()
func addDownloadedImage(_ image: UIImage?, for url: URL) {
lock.lock(); defer {
lock.unlock()
}
downloadedImages[url] = image
allImagesDownloaded.fulfill()
counter += 1
print("[imagedownloader] fulfillment progress \(counter)/\(imageUrls.count)")
}

let allImagesDownloaded = expectation(description: "All Images Downloaded")
allImagesDownloaded.expectedFulfillmentCount = imageUrls.count

for imageUrl in imageUrls {
concurrentOvercommitQueue.async {
self.downloader.download(with: imageUrl) { cachedResponse, error in
Expand All @@ -228,7 +232,6 @@ class ImageDownloaderTests: TestCase {
image = UIImage(data: data, scale: UIScreen.main.scale)
}
addDownloadedImage(image, for: imageUrl)
allImagesDownloaded.fulfill()
}
}
}
Expand Down

0 comments on commit 20dd048

Please sign in to comment.