Skip to content

Commit

Permalink
mock test for DestroyShard
Browse files Browse the repository at this point in the history
  • Loading branch information
LexLuthr committed Jul 11, 2022
1 parent 2b63a9d commit 89b3119
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions markets/dagstore/wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

// TestWrapperAcquireRecovery verifies that if acquire shard returns a "not found"
// error, the wrapper will attempt to register the shard then reacquire
func TestWrapperAcquireRecovery(t *testing.T) {
func TestWrapperAcquireRecoveryDestroy(t *testing.T) {
ctx := context.Background()
pieceCid, err := cid.Parse("bafkqaaa")
require.NoError(t, err)
Expand All @@ -48,6 +48,7 @@ func TestWrapperAcquireRecovery(t *testing.T) {
Accessor: getShardAccessor(t),
},
register: make(chan shard.Key, 1),
destroy: make(chan shard.Key, 1),
}
w.dagst = mock

Expand All @@ -73,6 +74,27 @@ func TestWrapperAcquireRecovery(t *testing.T) {
count++
}
require.Greater(t, count, 0)

// Destroy the shard
dr := make(chan dagstore.ShardResult, 1)
err = w.DestroyShard(ctx, pieceCid, dr)

dctx, cancel := context.WithTimeout(ctx, time.Second)
defer cancel()
select {
case <-dctx.Done():
require.Fail(t, "failed to call register")
case k := <-mock.destroy:
require.Equal(t, k.String(), pieceCid.String())
}

var dcount int
dch, err := mybs.AllKeysChan(ctx)
require.NoError(t, err)
for range dch {
count++
}
require.Equal(t, dcount, 0)
}

// TestWrapperBackground verifies the behaviour of the background go routine
Expand Down Expand Up @@ -130,11 +152,14 @@ type mockDagStore struct {

gc chan struct{}
recover chan shard.Key
destroy chan shard.Key
close chan struct{}
}

func (m *mockDagStore) DestroyShard(ctx context.Context, key shard.Key, out chan dagstore.ShardResult, _ dagstore.DestroyOpts) error {
panic("implement me")
m.destroy <- key
out <- dagstore.ShardResult{Key: key}
return nil
}

func (m *mockDagStore) GetShardInfo(k shard.Key) (dagstore.ShardInfo, error) {
Expand Down

0 comments on commit 89b3119

Please sign in to comment.