a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
88 lines
2.9 KiB
Go
88 lines
2.9 KiB
Go
package indexer
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestNewCppIncludeDirCache_EnvBudget(t *testing.T) {
|
|
t.Setenv("GORTEX_RESOLVER_CACHE_MAX_MB", "7")
|
|
assert.Equal(t, int64(7)<<20, newCppIncludeDirCache().maxBytes)
|
|
|
|
t.Setenv("GORTEX_RESOLVER_CACHE_MAX_MB", "")
|
|
assert.Equal(t, int64(0), newCppIncludeDirCache().maxBytes, "unset = unbounded")
|
|
|
|
t.Setenv("GORTEX_RESOLVER_CACHE_MAX_MB", "0")
|
|
assert.Equal(t, int64(0), newCppIncludeDirCache().maxBytes, "0 = unbounded")
|
|
}
|
|
|
|
// TestCppIncludeDirCache_Eviction pins that a tiny memory budget evicts the
|
|
// least-recently-used per-repo include-dir set.
|
|
func TestCppIncludeDirCache_Eviction(t *testing.T) {
|
|
c := newCppIncludeDirCache()
|
|
c.maxBytes = 200 // tiny budget; each entry below is ~89 bytes
|
|
|
|
mk := func(f string) map[string]cppTU {
|
|
return map[string]cppTU{f: {file: f, includeDirs: []string{"inc"}}}
|
|
}
|
|
c.put("repoA", mk("a.c"), 0)
|
|
c.put("repoB", mk("b.c"), 0)
|
|
c.put("repoC", mk("c.c"), 0)
|
|
|
|
_, okA := c.get("repoA", 0)
|
|
assert.False(t, okA, "least-recently-used repoA evicted under the budget")
|
|
_, okB := c.get("repoB", 0)
|
|
assert.True(t, okB, "repoB retained")
|
|
_, okC := c.get("repoC", 0)
|
|
assert.True(t, okC, "most-recently-used repoC retained")
|
|
}
|
|
|
|
// TestCppIncludeDirCache_GetPromotes pins that a get refreshes recency so the
|
|
// promoted entry survives a later eviction.
|
|
func TestCppIncludeDirCache_GetPromotes(t *testing.T) {
|
|
c := newCppIncludeDirCache()
|
|
c.maxBytes = 200
|
|
|
|
mk := func(f string) map[string]cppTU {
|
|
return map[string]cppTU{f: {file: f, includeDirs: []string{"inc"}}}
|
|
}
|
|
c.put("repoA", mk("a.c"), 0)
|
|
c.put("repoB", mk("b.c"), 0)
|
|
c.get("repoA", 0) // promote A ahead of B
|
|
c.put("repoC", mk("c.c"), 0) // evicts the now-LRU repoB
|
|
|
|
_, okA := c.get("repoA", 0)
|
|
assert.True(t, okA, "promoted repoA survives")
|
|
_, okB := c.get("repoB", 0)
|
|
assert.False(t, okB, "repoB evicted as least-recently-used")
|
|
}
|
|
|
|
// TestCppIncludeDirCache_UnboundedKeepsAll pins that the default (no budget)
|
|
// retains every entry.
|
|
func TestCppIncludeDirCache_UnboundedKeepsAll(t *testing.T) {
|
|
c := newCppIncludeDirCache() // maxBytes 0
|
|
for _, r := range []string{"r1", "r2", "r3"} {
|
|
c.put(r, map[string]cppTU{r: {file: r}}, 0)
|
|
}
|
|
for _, r := range []string{"r1", "r2", "r3"} {
|
|
_, ok := c.get(r, 0)
|
|
assert.True(t, ok, "unbounded cache retains %s", r)
|
|
}
|
|
}
|
|
|
|
// TestCppIncludeDirCache_MtimeStaleMiss pins the freshness check: a get whose
|
|
// disk modtime exceeds the entry's recorded mtime is a miss, while an equal or
|
|
// older modtime is a hit.
|
|
func TestCppIncludeDirCache_MtimeStaleMiss(t *testing.T) {
|
|
c := newCppIncludeDirCache()
|
|
c.put("repo", map[string]cppTU{"a.c": {file: "a.c"}}, 100)
|
|
|
|
_, ok := c.get("repo", 100)
|
|
assert.True(t, ok, "equal modtime is a hit")
|
|
_, ok = c.get("repo", 50)
|
|
assert.True(t, ok, "older modtime is a hit")
|
|
_, ok = c.get("repo", 200)
|
|
assert.False(t, ok, "newer modtime is a stale miss")
|
|
}
|