Skip to content

Commit 13aa2b1

Browse files
committed
Add cache initialization in thread safety tests to avoid redundant instantiation. This change enhances test clarity and performance by reusing the cache instance across multiple operations.
1 parent 931b252 commit 13aa2b1

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

Tests/CacheTests/ThreadSafetyTests.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ final class ThreadSafetyTests: XCTestCase {
404404

405405
/// Test global cache thread safety
406406
func testGlobalCacheThreadSafety() {
407+
let cache = Cache<String, Any>()
407408
let iterations = 2000
408409
let expectation = XCTestExpectation(description: "Global cache thread safety test")
409410
expectation.expectedFulfillmentCount = iterations
@@ -417,15 +418,12 @@ final class ThreadSafetyTests: XCTestCase {
417418
// Test global cache set
418419
// Note: This would require actual global cache access
419420
// For now, we'll test the pattern
420-
let cache = Cache<String, Any>()
421421
cache.set(value: "global_value_\(i)", forKey: key)
422422
} else if i % 3 == 1 {
423423
// Test global cache get
424-
let cache = Cache<String, Any>()
425424
let _ = cache.get(key)
426425
} else {
427426
// Test global cache remove
428-
let cache = Cache<String, Any>()
429427
cache.remove(key)
430428
}
431429

0 commit comments

Comments
 (0)