Skip to content

Commit 4f415aa

Browse files
fix: further increase TTL test timeouts for macOS CI reliability
- Increase updateAgeOnGet test TTL from 1s to 2s and adjust sleep times - Increase getRemainingTTL test TTL from 2s to 5s for more tolerance - Adjust timing assertions to have wider acceptable ranges - These changes specifically address macOS CI timing issues The tests were passing on Ubuntu but failing on macOS due to different timing characteristics in the CI environments.
1 parent 8da3579 commit 4f415aa

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Tests/SwiftLRUCacheTests/TTLTests.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ struct TTLTests {
5050

5151
@Test("Cache updates TTL on set when updateAgeOnGet is true")
5252
func testUpdateAgeOnGet() async throws {
53-
var config = try Configuration<String, Int>(max: 10, ttl: 1.0) // 1 second (increased from 200ms)
53+
var config = try Configuration<String, Int>(max: 10, ttl: 2.0) // 2 seconds TTL
5454
config.updateAgeOnGet = true
5555
let cache = LRUCache<String, Int>(configuration: config)
5656

5757
cache.set("key1", value: 100)
5858

59-
try await Task.sleep(nanoseconds: 400_000_000) // Sleep 400ms
60-
_ = cache.get("key1") // This should refresh TTL
59+
try await Task.sleep(nanoseconds: 1_000_000_000) // Sleep 1 second
60+
_ = cache.get("key1") // This should refresh TTL, giving another 2 seconds
6161

62-
try await Task.sleep(nanoseconds: 800_000_000) // Sleep another 800ms
62+
try await Task.sleep(nanoseconds: 1_500_000_000) // Sleep 1.5 seconds (still within the refreshed 2 second TTL)
6363

6464
#expect(cache.get("key1") == 100) // Should still be valid due to refresh
6565
}
@@ -126,19 +126,19 @@ struct TTLTests {
126126
let config = try Configuration<String, Int>(max: 10)
127127
let cache = LRUCache<String, Int>(configuration: config)
128128

129-
cache.set("key1", value: 100, ttl: 2) // 2 seconds TTL (increased from 1)
129+
cache.set("key1", value: 100, ttl: 5) // 5 seconds TTL for more tolerance
130130

131131
let remaining1 = cache.getRemainingTTL("key1")
132132
#expect(remaining1 != nil)
133-
#expect(remaining1! > 1.8) // Allow for some execution time
134-
#expect(remaining1! <= 2.0)
133+
#expect(remaining1! > 4.5) // Allow up to 500ms for execution time
134+
#expect(remaining1! <= 5.0)
135135

136-
try await Task.sleep(nanoseconds: 1_000_000_000) // Sleep 1 second
136+
try await Task.sleep(nanoseconds: 2_000_000_000) // Sleep 2 seconds
137137

138138
let remaining2 = cache.getRemainingTTL("key1")
139139
#expect(remaining2 != nil)
140-
#expect(remaining2! > 0.8) // More tolerance (was 0.4)
141-
#expect(remaining2! < 1.2) // More tolerance (was 0.6)
140+
#expect(remaining2! > 2.5) // Should have at least 2.5 seconds left
141+
#expect(remaining2! < 3.5) // But less than 3.5 seconds
142142
}
143143

144144
@Test("Cache respects ttlAutopurge setting")

0 commit comments

Comments
 (0)