MCPcopy
hub / github.com/nextlevelbuilder/goclaw / TestInMemoryCache_Close

Function TestInMemoryCache_Close

internal/cache/memory_test.go:143–158  ·  view source on GitHub ↗

TestInMemoryCache_Close verifies Close stops the sweep goroutine (no leak).

(t *testing.T)

Source from the content-addressed store, hash-verified

141
142// TestInMemoryCache_Close verifies Close stops the sweep goroutine (no leak).
143func TestInMemoryCache_Close(t *testing.T) {
144 c := NewInMemoryCache[string](
145 WithSweepInterval[string](10 * time.Millisecond),
146 )
147 ctx := context.Background()
148 c.Set(ctx, "k", "v", 0)
149
150 c.Close()
151 // Close should be idempotent
152 c.Close()
153
154 // After Close, cache is still readable for lazy access but sweep is stopped
155 if _, ok := c.Get(ctx, "k"); !ok {
156 t.Error("Get should still work after Close")
157 }
158}
159
160// TestInMemoryCache_ConcurrentSweepAndSet verifies no race between sweep and Set.
161func TestInMemoryCache_ConcurrentSweepAndSet(t *testing.T) {

Callers

nothing calls this directly

Calls 4

SetMethod · 0.65
CloseMethod · 0.65
GetMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected