Skip to content

[repo-assist] test: add coverage for in-memory cache (Caching.fs) - #493

Merged
sergey-tihon merged 2 commits into
masterfrom
repo-assist/test-caching-coverage-c1a8c64f16c96479
Sep 9, 2026
Merged

[repo-assist] test: add coverage for in-memory cache (Caching.fs)#493
sergey-tihon merged 2 commits into
masterfrom
repo-assist/test-caching-coverage-c1a8c64f16c96479

Conversation

@github-actions

@github-actions github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

🤖 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 by Provider.OpenApiClient.fs to cache generated provided types across compilation runs.

What's covered

11 new tests in tests/SwaggerProvider.Tests/CachingTests.fs:

  • TryRetrieve returns None for missing keys
  • Set + TryRetrieve round-trips a value
  • Set overwrites an existing value for the same key
  • Remove deletes a value (and is a safe no-op for a missing key)
  • GetOrAdd invokes the factory exactly once and returns the cached value on subsequent calls
  • Independent caching across different keys
  • Expiration: entries become unavailable once the TTL elapses
  • extendCacheExpiration correctly resets the expiration window when set to true, and does not when omitted

Rationale

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

  • Build: dotnet build SwaggerProvider.sln -c Release succeeded (pre-existing warnings only, unrelated).
  • Format: dotnet fantomas --check tests/SwaggerProvider.Tests/CachingTests.fs passes.
  • Unit tests: 573/573 passed (562 → 573, 11 new tests), 1 pre-existing skip.

Trade-offs

  • Two tests rely on short Thread.Sleep timings (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.

Generated by 🌈 Repo Assist, see workflow run. Learn more.
Comment /repo-assist to run again

Add this agentic workflow to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@ae8d551f07c7ed7619f8c58c7bb4c3ac89395d38

…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>
@sergey-tihon
sergey-tihon marked this pull request as ready for review September 9, 2026 18:44
Copilot AI lite review requested due to automatic review settings September 9, 2026 18:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.fs with 11 new unit tests targeting createInMemoryCache behaviors, including expiration and extendCacheExpiration.
  • Register the new test file in SwaggerProvider.Tests.fsproj so 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 TryRetrieve can 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.

Comment thread tests/SwaggerProvider.Tests/CachingTests.fs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@sergey-tihon
sergey-tihon merged commit cacf7ed into master Sep 9, 2026
2 checks passed
@sergey-tihon
sergey-tihon deleted the repo-assist/test-caching-coverage-c1a8c64f16c96479 branch September 9, 2026 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants