File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 1+ package bolt
2+
3+ import (
4+ "testing"
5+ )
6+
7+ func TestTx_allocatePageStats (t * testing.T ) {
8+ f := newFreelist ()
9+ f .ids = []pgid {2 , 3 }
10+
11+ tx := & Tx {
12+ db : & DB {
13+ freelist : f ,
14+ pageSize : defaultPageSize ,
15+ },
16+ meta : & meta {},
17+ pages : make (map [pgid ]* page ),
18+ }
19+
20+ prePageCnt := tx .Stats ().PageCount
21+ allocateCnt := f .free_count ()
22+
23+ if _ , err := tx .allocate (allocateCnt ); err != nil {
24+ t .Fatal (err )
25+ }
26+
27+ if tx .Stats ().PageCount != prePageCnt + allocateCnt {
28+ t .Errorf ("Allocated %d but got %d page in stats" , allocateCnt , tx .Stats ().PageCount )
29+ }
30+ }
Original file line number Diff line number Diff line change @@ -483,7 +483,7 @@ func (tx *Tx) allocate(count int) (*page, error) {
483483 tx .pages [p .id ] = p
484484
485485 // Update statistics.
486- tx .stats .PageCount ++
486+ tx .stats .PageCount += count
487487 tx .stats .PageAlloc += count * tx .db .pageSize
488488
489489 return p , nil
You can’t perform that action at this time.
0 commit comments