Skip to content

Commit 1bbc902

Browse files
obj-pclaude
andauthored
Replace flaky timing assertion with structural cache-hit check (#90)
The warm-cache integration test used a wall-clock threshold (3s) that failed on CI shared runners where subprocess overhead can exceed 4s. Replace with a structural assertion: verify no new cache file is written on the second build, which proves the cache was hit without depending on absolute timing. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c8c0fdc commit 1bbc902

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

Tests/PreviewsCoreTests/SetupCacheTests.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -362,29 +362,26 @@ struct SetupCacheTests {
362362
defer { try? FileManager.default.removeItem(at: dir) }
363363

364364
// Cold build
365-
let clock = ContinuousClock()
366-
let coldStart = clock.now
367365
let coldResult = try await SetupBuilder.build(
368366
config: config, configDirectory: dir, platform: .macOS)
369-
let coldDuration = clock.now - coldStart
370367

371368
// Verify cache file exists on disk
372369
let cacheDir = dir.appendingPathComponent(".build/\(SetupCache.cacheDirectory)")
373-
let cacheFiles = try? FileManager.default.contentsOfDirectory(
370+
let filesAfterCold = try FileManager.default.contentsOfDirectory(
374371
at: cacheDir, includingPropertiesForKeys: nil)
375-
#expect((cacheFiles?.count ?? 0) >= 1, "Cache file should exist after cold build")
372+
#expect(filesAfterCold.count >= 1, "Cache file should exist after cold build")
376373

377374
// Warm build
378-
let warmStart = clock.now
379375
let warmResult = try await SetupBuilder.build(
380376
config: config, configDirectory: dir, platform: .macOS)
381-
let warmDuration = clock.now - warmStart
382377

378+
// No new cache file written — proves the cache was hit, not rebuilt
379+
let filesAfterWarm = try FileManager.default.contentsOfDirectory(
380+
at: cacheDir, includingPropertiesForKeys: nil)
383381
#expect(coldResult == warmResult, "Warm result must equal cold result")
384-
// Threshold is generous for CI shared runners where subprocess overhead is higher
385382
#expect(
386-
warmDuration < .seconds(3),
387-
"Warm build (\(warmDuration)) should complete in under 3s")
383+
filesAfterWarm.count == filesAfterCold.count,
384+
"No new cache entry should be written on cache hit")
388385
}
389386

390387
@Test("Source change invalidates cache and triggers rebuild")

0 commit comments

Comments
 (0)