(t *testing.T)
| 356 | } |
| 357 | |
| 358 | func TestFreelist_E2E_HappyPath(t *testing.T) { |
| 359 | f := newTestFreelist() |
| 360 | f.Init([]common.Pgid{}) |
| 361 | requirePages(t, f, common.Pgids{}, common.Pgids{}) |
| 362 | |
| 363 | allocated := f.Allocate(common.Txid(1), 5) |
| 364 | require.Equal(t, common.Pgid(0), allocated) |
| 365 | // tx.go may now allocate more space, and eventually we need to delete a page again |
| 366 | f.Free(common.Txid(2), common.NewPage(5, common.LeafPageFlag, 0, 0)) |
| 367 | f.Free(common.Txid(2), common.NewPage(3, common.LeafPageFlag, 0, 0)) |
| 368 | f.Free(common.Txid(2), common.NewPage(8, common.LeafPageFlag, 0, 0)) |
| 369 | // the above will only mark the pages as pending, so free pages should not return anything |
| 370 | requirePages(t, f, common.Pgids{}, common.Pgids{3, 5, 8}) |
| 371 | |
| 372 | // someone wants to do a read on top of the next tx id |
| 373 | f.AddReadonlyTXID(common.Txid(3)) |
| 374 | // this should free the above pages for tx 2 entirely |
| 375 | f.ReleasePendingPages() |
| 376 | requirePages(t, f, common.Pgids{3, 5, 8}, common.Pgids{}) |
| 377 | |
| 378 | // no span of two pages available should yield a zero-page result |
| 379 | require.Equal(t, common.Pgid(0), f.Allocate(common.Txid(4), 2)) |
| 380 | // we should be able to allocate those pages independently however, |
| 381 | // map and array differ in the order they return the pages |
| 382 | expectedPgids := map[common.Pgid]struct{}{3: {}, 5: {}, 8: {}} |
| 383 | for i := 0; i < 3; i++ { |
| 384 | allocated = f.Allocate(common.Txid(4), 1) |
| 385 | require.Contains(t, expectedPgids, allocated, "expected to find pgid %d", allocated) |
| 386 | require.False(t, f.Freed(allocated)) |
| 387 | delete(expectedPgids, allocated) |
| 388 | } |
| 389 | require.Emptyf(t, expectedPgids, "unexpectedly more than one page was still found") |
| 390 | // no more free pages to allocate |
| 391 | require.Equal(t, common.Pgid(0), f.Allocate(common.Txid(4), 1)) |
| 392 | } |
| 393 | |
| 394 | func TestFreelist_E2E_MultiSpanOverflows(t *testing.T) { |
| 395 | f := newTestFreelist() |
nothing calls this directly
no test coverage detected