Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
max-hoffman committed Mar 29, 2024
1 parent ef4341b commit 30427de
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 23 deletions.
13 changes: 9 additions & 4 deletions go/store/chunks/chunk_store_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ type ChunkStoreTestSuite struct {
Factory *memoryStoreFactory
}

func noopGetAddrs(ctx context.Context, c Chunk) (hash.HashSet, error) {
return nil, nil
func noopGetAddrs(c Chunk) GetAddrsCurry {
return func(ctx context.Context, addrs hash.HashSet) error {
return nil
}
}

func (suite *ChunkStoreTestSuite) TestChunkStorePut() {
Expand All @@ -55,8 +57,11 @@ func (suite *ChunkStoreTestSuite) TestChunkStorePut() {
// Put chunk with dangling ref should error on Commit
data := []byte("bcd")
nc := NewChunk(data)
err = store.Put(ctx, nc, func(ctx context.Context, c Chunk) (hash.HashSet, error) {
return hash.NewHashSet(hash.Of([]byte("nonsense"))), nil
err = store.Put(ctx, nc, func(c Chunk) GetAddrsCurry {
return func(ctx context.Context, addrs hash.HashSet) error {
addrs.Insert(hash.Of([]byte("nonsense")))
return nil
}
})
suite.NoError(err)
root, err := store.Root(ctx)
Expand Down
13 changes: 9 additions & 4 deletions go/store/nbs/block_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ func (suite *BlockStoreSuite) TestChunkStoreNotDir() {
suite.Error(err)
}

func noopGetAddrs(ctx context.Context, c chunks.Chunk) (hash.HashSet, error) {
return nil, nil
func noopGetAddrs(c chunks.Chunk) chunks.GetAddrsCurry {
return func(ctx context.Context, addrs hash.HashSet) error {
return nil
}
}

func (suite *BlockStoreSuite) TestChunkStorePut() {
Expand Down Expand Up @@ -159,8 +161,11 @@ func (suite *BlockStoreSuite) TestChunkStorePut() {

// Put chunk with dangling ref should error on Commit
nc := chunks.NewChunk([]byte("bcd"))
err = suite.store.Put(context.Background(), nc, func(ctx context.Context, c chunks.Chunk) (hash.HashSet, error) {
return hash.NewHashSet(hash.Of([]byte("lorem ipsum"))), nil
err = suite.store.Put(context.Background(), nc, func(c chunks.Chunk) chunks.GetAddrsCurry {
return func(ctx context.Context, addrs hash.HashSet) error {
addrs.Insert(hash.Of([]byte("lorem ipsum")))
return nil
}
})
suite.NoError(err)
root, err := suite.store.Root(context.Background())
Expand Down
8 changes: 2 additions & 6 deletions go/store/nbs/root_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ func TestChunkStoreVersion(t *testing.T) {

assert.Equal(constants.FormatLD1String, store.Version())
newChunk := chunks.NewChunk([]byte("new root"))
require.NoError(t, store.Put(context.Background(), newChunk, func(ctx context.Context, c chunks.Chunk) (hash.HashSet, error) {
return nil, nil
}))
require.NoError(t, store.Put(context.Background(), newChunk, noopGetAddrs))
newRoot := newChunk.Hash()

if assert.True(store.Commit(context.Background(), newRoot, hash.Hash{})) {
Expand Down Expand Up @@ -213,9 +211,7 @@ func TestChunkStoreCommitOptimisticLockFail(t *testing.T) {
require.NoError(t, err)

newChunk := chunks.NewChunk([]byte("new root 2"))
require.NoError(t, store.Put(context.Background(), newChunk, func(ctx context.Context, c chunks.Chunk) (hash.HashSet, error) {
return nil, nil
}))
require.NoError(t, store.Put(context.Background(), newChunk, noopGetAddrs))
newRoot2 := newChunk.Hash()
success, err := store.Commit(context.Background(), newRoot2, hash.Hash{})
require.NoError(t, err)
Expand Down
8 changes: 7 additions & 1 deletion go/store/nbs/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,13 @@ func TestNBSPruneTableFiles(t *testing.T) {

// add a chunk and flush to trigger a conjoin
c := chunks.NewChunk([]byte("it's a boy!"))
ok, err := st.addChunk(ctx, c, hash.NewHashSet(), st.hasMany)
addrs := hash.NewHashSet()
ok, err := st.addChunk(ctx, c, func(c chunks.Chunk) chunks.GetAddrsCurry {
return func(ctx context.Context, _ hash.HashSet) error {
addrs.Insert(c.Hash())
return nil
}
}, st.hasMany)
require.NoError(t, err)
require.True(t, ok)
ok, err = st.Commit(ctx, st.upstream.root, st.upstream.root)
Expand Down
11 changes: 5 additions & 6 deletions go/store/nbs/table_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,12 @@ func (ts tableSet) Size() int {
// append adds a memTable to an existing tableSet, compacting |mt| and
// returning a new tableSet with newly compacted table added.
func (ts tableSet) append(ctx context.Context, mt *memTable, checker refCheck, hasCache *lru.TwoQueueCache[hash.Hash, struct{}], stats *Stats) (tableSet, error) {
if true {
addrs := hash.NewHashSet()
for _, getAddrs := range mt.getChildAddrs {
getAddrs(ctx, addrs)
}
mt.addChildRefs(addrs)
addrs := hash.NewHashSet()
for _, getAddrs := range mt.getChildAddrs {
getAddrs(ctx, addrs)
}
mt.addChildRefs(addrs)

for i := range mt.pendingRefs {
if !mt.pendingRefs[i].has && hasCache.Contains(*mt.pendingRefs[i].a) {
mt.pendingRefs[i].has = true
Expand Down
6 changes: 4 additions & 2 deletions go/store/spec/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,10 @@ func (t *testProtocol) NewDatabase(sp Spec) (datas.Database, error) {
return datas.NewDatabase(cs), nil
}

func noopGetAddrs(ctx context.Context, c chunks.Chunk) (hash.HashSet, error) {
return nil, nil
func noopGetAddrs(c chunks.Chunk) chunks.GetAddrsCurry {
return func(ctx context.Context, addrs hash.HashSet) error {
return nil
}
}

func TestExternalProtocol(t *testing.T) {
Expand Down

0 comments on commit 30427de

Please sign in to comment.