[repo-assist] test: add coverage for in-memory cache (Caching.fs) - #493
Merged
sergey-tihon merged 2 commits intoSep 9, 2026
Merged
Conversation
…ryCache The in-memory ICache implementation in Caching.fs (used by Provider.OpenApiClient.fs to cache generated provided types) had zero direct unit tests. Added 11 tests covering Set/TryRetrieve/Remove/GetOrAdd basic behavior, per-key isolation, missing-key handling, factory invocation counts, expiration after the TTL elapses, and the extendCacheExpiration flag's effect on the expiration window. 562 -> 573 unit tests, all passing. Build and fantomas --check pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The TTL tests use tight Thread.Sleep timing relative to the configured expiration, which can cause intermittent CI failures under scheduler jitter.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds new unit-test coverage for the in-memory cache implementation (SwaggerProvider.Caching.createInMemoryCache) to validate basic cache behaviors (set/get/remove/get-or-add) and TTL-based expiration semantics used by the type provider pipeline.
Changes:
- Add
CachingTests.fswith 11 new unit tests targetingcreateInMemoryCachebehaviors, including expiration andextendCacheExpiration. - Register the new test file in
SwaggerProvider.Tests.fsprojso it compiles/runs as part of the unit test suite.
File summaries
| File | Description |
|---|---|
| tests/SwaggerProvider.Tests/SwaggerProvider.Tests.fsproj | Adds CachingTests.fs to the test project compile items. |
| tests/SwaggerProvider.Tests/CachingTests.fs | Introduces unit tests for the in-memory cache, including TTL expiration and extension behavior. |
Review details
Suppressed comments (1)
tests/SwaggerProvider.Tests/CachingTests.fs:109
- This test also depends on relatively tight wall-clock timing (100ms TTL with 60ms + 80ms sleeps). If the first sleep overshoots significantly, the intermediate
TryRetrievecan already be expired, causing sporadic failures. Increasing the TTL and using proportionally larger margins will make the test more robust.
let cache = createInMemoryCache(TimeSpan.FromMilliseconds 100.0)
cache.Set("key1", "value")
Thread.Sleep(60)
cache.TryRetrieve("key1") |> shouldEqual(Some "value")
Thread.Sleep(80)
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
sergey-tihon
deleted the
repo-assist/test-caching-coverage-c1a8c64f16c96479
branch
September 9, 2026 19:00
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created automatically by Repo Assist, an AI assistant.
Summary
Adds unit test coverage for
SwaggerProvider.Caching.createInMemoryCache(src/SwaggerProvider.DesignTime/Caching.fs), which previously had zero direct tests despite being a non-trivial concurrent, time-based cache used byProvider.OpenApiClient.fsto cache generated provided types across compilation runs.What's covered
11 new tests in
tests/SwaggerProvider.Tests/CachingTests.fs:TryRetrievereturnsNonefor missing keysSet+TryRetrieveround-trips a valueSetoverwrites an existing value for the same keyRemovedeletes a value (and is a safe no-op for a missing key)GetOrAddinvokes the factory exactly once and returns the cached value on subsequent callsextendCacheExpirationcorrectly resets the expiration window when set totrue, and does not when omittedRationale
This cache directly affects type provider correctness (stale/duplicate type generation) and was completely untested. The tests are fast (short TTLs, ms-scale sleeps) and deterministic.
Test Status
dotnet build SwaggerProvider.sln -c Releasesucceeded (pre-existing warnings only, unrelated).dotnet fantomas --check tests/SwaggerProvider.Tests/CachingTests.fspasses.Trade-offs
Thread.Sleeptimings (20–150ms) to exercise expiration; these are intentionally generous relative to the sleep durations to avoid flakiness, consistent with the cache's existing polling-based invalidation design.Add this agentic workflow to your repo
To install this agentic workflow, run