Skip to content

Commit

Permalink
Additional queue tests
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Erik Ingenito <erik@carbonfive.com>
  • Loading branch information
Erik Ingenito committed Mar 16, 2019
1 parent 6c1eca9 commit 55f02ea
Showing 1 changed file with 56 additions and 4 deletions.
60 changes: 56 additions & 4 deletions provider/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"testing"
"time"

cid "github.com/ipfs/go-cid"
datastore "github.com/ipfs/go-datastore"
sync "github.com/ipfs/go-datastore/sync"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/sync"
)

func makeCids(n int) []cid.Cid {
Expand Down Expand Up @@ -52,7 +52,7 @@ func TestBasicOperation(t *testing.T) {
assertOrdered(cids, queue, t)
}

func TestInitialization(t *testing.T) {
func TestSparseDatastore(t *testing.T) {
ctx := context.Background()
defer ctx.Done()

Expand All @@ -63,7 +63,59 @@ func TestInitialization(t *testing.T) {
}

cids := makeCids(10)
for _, c := range cids {
queue.Enqueue(c)
}

// remove entries in the middle
err = queue.ds.Delete(queue.queueKey(5))
if err != nil {
t.Fatal(err)
}

err = queue.ds.Delete(queue.queueKey(6))
if err != nil {
t.Fatal(err)
}

expected := append(cids[:5], cids[7:]...)
assertOrdered(expected, queue, t)
}

func TestMangledData(t *testing.T) {
ctx := context.Background()
defer ctx.Done()

ds := sync.MutexWrap(datastore.NewMapDatastore())
queue, err := NewQueue(ctx, "test", ds)
if err != nil {
t.Fatal(err)
}

cids := makeCids(10)
for _, c := range cids {
queue.Enqueue(c)
}

// remove entries in the middle
err = queue.ds.Put(queue.queueKey(5), []byte("borked"))

expected := append(cids[:5], cids[6:]...)
assertOrdered(expected, queue, t)
}


func TestInitialization(t *testing.T) {
ctx := context.Background()
defer ctx.Done()

ds := sync.MutexWrap(datastore.NewMapDatastore())
queue, err := NewQueue(ctx, "test", ds)
if err != nil {
t.Fatal(err)
}

cids := makeCids(10)
for _, c := range cids {
queue.Enqueue(c)
}
Expand Down

0 comments on commit 55f02ea

Please sign in to comment.