MCPcopy
hub / github.com/perkeep/perkeep / TestClose

Function TestClose

pkg/blobserver/diskpacked/diskpacked_test.go:297–335  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

295}
296
297func TestClose(t *testing.T) {
298 fds := func() (n int) {
299 openFdsVar.Do(func(kv expvar.KeyValue) {
300 if i, ok := kv.Value.(*expvar.Int); ok {
301 inc, _ := strconv.Atoi(i.String())
302 n += inc
303 }
304 })
305 return
306 }
307
308 fd0 := fds()
309 sto := newTempDiskpackedMemory(t)
310 fd1 := fds()
311
312 s := sto.(*storage)
313
314 const blobSize = 5 << 10
315 b := &test.Blob{Contents: strings.Repeat("a", blobSize)}
316 br := b.BlobRef()
317
318 fd2 := fds()
319 _, err := blobserver.Receive(ctxbg, sto, br, b.Reader())
320 if err != nil {
321 t.Fatal(err)
322 }
323 fd3 := fds()
324
325 if err := s.Close(); err != nil {
326 t.Fatalf("Close: %v", err)
327 }
328 fd4 := fds()
329 got := [...]int{fd1 - fd0, fd2 - fd1, fd3 - fd2, fd4 - fd3}
330 want := [...]int{+2, 0, 0, -2}
331 if got != want {
332 t.Errorf("fd count over time = %v; want %v", got, want)
333 }
334
335}
336
337func TestBadDir(t *testing.T) {
338 s, err := newStorage("hopefully this is a not existing directory", 1<<20, jsonconfig.Obj{"type": "memory"})

Callers

nothing calls this directly

Calls 8

BlobRefMethod · 0.95
ReaderMethod · 0.95
ReceiveFunction · 0.92
newTempDiskpackedMemoryFunction · 0.85
FatalMethod · 0.80
CloseMethod · 0.65
FatalfMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected