Skip to content

Commit

Permalink
add freelist interface unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Jungblut <tjungblu@redhat.com>
  • Loading branch information
tjungblu committed Aug 6, 2024
1 parent 978df69 commit 629ac9c
Show file tree
Hide file tree
Showing 4 changed files with 356 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/freelist/array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"reflect"
"testing"

"github.com/stretchr/testify/require"

"go.etcd.io/bbolt/internal/common"
)

Expand Down Expand Up @@ -50,3 +52,12 @@ func TestFreelistArray_allocate(t *testing.T) {
t.Fatalf("exp=%v; got=%v", exp, f.freePageIds())
}
}

func TestInvalidArrayAllocation(t *testing.T) {
f := NewArrayFreelist()
ids := []common.Pgid{1}
f.Init(ids)
require.Panics(t, func() {
f.Allocate(common.Txid(1), 1)
})
}
1 change: 1 addition & 0 deletions internal/freelist/freelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Interface interface {
Freed(pgId common.Pgid) bool

// Rollback removes the pages from a given pending tx.
// Should always be followed by Reload or NoSyncReload from last freelist state.
Rollback(txId common.Txid)

// Copyall copies a list of all free ids and all pending ids in one sorted list.
Expand Down
Loading

0 comments on commit 629ac9c

Please sign in to comment.