MCPcopy
hub / github.com/etcd-io/bbolt / TestFreelist_write

Function TestFreelist_write

internal/freelist/freelist_test.go:336–356  ·  view source on GitHub ↗

Ensure that a freelist can serialize into a freelist page.

(t *testing.T)

Source from the content-addressed store, hash-verified

334
335// Ensure that a freelist can serialize into a freelist page.
336func TestFreelist_write(t *testing.T) {
337 // Create a freelist and write it to a page.
338 var buf [4096]byte
339 f := newTestFreelist()
340
341 f.Init([]common.Pgid{12, 39})
342 f.pendingPageIds()[100] = &txPending{ids: []common.Pgid{28, 11}}
343 f.pendingPageIds()[101] = &txPending{ids: []common.Pgid{3}}
344 p := (*common.Page)(unsafe.Pointer(&buf[0]))
345 f.Write(p)
346
347 // Read the page back out.
348 f2 := newTestFreelist()
349 f2.Read(p)
350
351 // Ensure that the freelist is correct.
352 // All pages should be present and in reverse order.
353 if exp := common.Pgids([]common.Pgid{3, 11, 12, 28, 39}); !reflect.DeepEqual(exp, f2.freePageIds()) {
354 t.Fatalf("exp=%v; got=%v", exp, f2.freePageIds())
355 }
356}
357
358func TestFreelist_E2E_HappyPath(t *testing.T) {
359 f := newTestFreelist()

Callers

nothing calls this directly

Calls 8

PgidsTypeAlias · 0.92
newTestFreelistFunction · 0.85
InitMethod · 0.65
pendingPageIdsMethod · 0.65
WriteMethod · 0.65
ReadMethod · 0.65
freePageIdsMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected