Browse Source

Fix a flaky test due to task env

onevcat 1 year ago
parent
commit
c13a80507c
1 changed files with 5 additions and 8 deletions
  1. 5 8
      Tests/KingfisherTests/ImageCacheTests.swift

+ 5 - 8
Tests/KingfisherTests/ImageCacheTests.swift

@@ -310,18 +310,15 @@ class ImageCacheTests: XCTestCase {
         XCTAssertTrue(cachePath.hasSuffix(".jpg"))
     }
   
-    func testCachedImageIsFetchedSynchronouslyFromTheMemoryCache() {
+    @MainActor func testCachedImageIsFetchedSynchronouslyFromTheMemoryCache() {
         cache.store(testImage, forKey: testKeys[0], toDisk: false)
-        let foundImage = ActorBox<KFCrossPlatformImage?>(nil)
+        var image: KFCrossPlatformImage? = nil
         cache.retrieveImage(forKey: testKeys[0]) { result in
-            Task {
-                await foundImage.setValue(result.value?.image)
+            MainActor.assumeIsolated {
+                image = try? result.get().image
             }
         }
-        Task {
-            let value = await foundImage.value
-            XCTAssertEqual(testImage, value)
-        }
+        XCTAssertEqual(testImage, image)
     }
     
     func testCachedImageIsFetchedSynchronouslyFromTheMemoryCacheAsync() async throws {