MCPcopy
hub / github.com/golang/tools / TestFutureCache_Persistent

Function TestFutureCache_Persistent

gopls/internal/cache/future_test.go:17–36  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestFutureCache_Persistent(t *testing.T) {
18 c := newFutureCache[int, int](true)
19 ctx := context.Background()
20
21 var computed atomic.Int32
22 compute := func(i int) cacheFunc[int] {
23 return func(context.Context) (int, error) {
24 computed.Add(1)
25 return i, ctx.Err()
26 }
27 }
28
29 testFutureCache(t, ctx, c, compute)
30
31 // Since this cache is persistent, we should get exactly 10 computations,
32 // since there are 10 distinct keys in [testFutureCache].
33 if got := computed.Load(); got != 10 {
34 t.Errorf("computed %d times, want 10", got)
35 }
36}
37
38func TestFutureCache_Ephemeral(t *testing.T) {
39 c := newFutureCache[int, int](false)

Callers

nothing calls this directly

Calls 5

testFutureCacheFunction · 0.85
ErrMethod · 0.65
ErrorfMethod · 0.65
AddMethod · 0.45
LoadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…