MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestPutStreamRoundTrip

Function TestPutStreamRoundTrip

cmd/cache-proxy/cache_test.go:222–252  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

220 for _, k := range keys {
221 if _, err := c.PutStream(k, bytes.NewReader(make([]byte, 60))); err != nil {
222 t.Fatalf("PutStream %s: %v", k, err)
223 }
224 }
225 // After three 60-byte puts with maxBytes=100, the first key must have
226 // been evicted (oldest lastAccess).
227 if c.Has(keys[0]) {
228 t.Error("oldest entry should have been evicted")
229 }
230 // The most recent must still be present.
231 if !c.Has(keys[2]) {
232 t.Error("newest entry should still be cached")
233 }
234}
235
236func TestDiskCacheEntryLimitEvictsOldest(t *testing.T) {
237 c := newTestCache(t)
238 c.maxEntries = 2
239 keys := []string{strings.Repeat("4", 64), strings.Repeat("5", 64), strings.Repeat("6", 64)}
240 for _, key := range keys {
241 if _, err := c.PutStream(key, bytes.NewReader([]byte("x"))); err != nil {
242 t.Fatal(err)
243 }
244 }
245 if c.order.Len() != 2 || c.Has(keys[0]) || !c.Has(keys[1]) || !c.Has(keys[2]) {
246 t.Fatalf("entry-limited cache retained unexpected keys: len=%d first=%t second=%t third=%t", c.order.Len(), c.Has(keys[0]), c.Has(keys[1]), c.Has(keys[2]))
247 }
248}
249
250func TestDiskCacheHardEntryLimitAppliesDuringStartupScan(t *testing.T) {
251 dir := t.TempDir()
252 entries := []struct {
253 key string
254 when time.Time
255 }{

Callers

nothing calls this directly

Calls 6

newTestCacheFunction · 0.85
tmpDirEntriesFunction · 0.85
PutStreamMethod · 0.80
HasMethod · 0.80
CloseMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected