Skip to content

Commit

Permalink
additional logging
Browse files Browse the repository at this point in the history
  • Loading branch information
azarovalex committed Jan 22, 2024
1 parent e9e3d0a commit 95a5456
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 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,15 +232,14 @@ class ImageDownloaderTests: TestCase {
image = UIImage(data: data, scale: UIScreen.main.scale)
}
addDownloadedImage(image, for: imageUrl)
allImagesDownloaded.fulfill()
}
}
}

for imageUrl in imageUrls {
concurrentOvercommitQueue.async {
/// `activeOperation(with:)` should be thread safe
_ = self.downloader.activeOperation(with: imageUrl)
// _ = self.downloader.activeOperation(with: imageUrl)
}
}

Expand Down

0 comments on commit 95a5456

Please sign in to comment.