提交 09cc62eb 作者: Erik Ingenito

Additional provider tests

License: MIT
Signed-off-by: 's avatarErik Ingenito <erik@carbonfive.com>
上级 906d2bd0
...@@ -19,6 +19,15 @@ type mockRouting struct { ...@@ -19,6 +19,15 @@ type mockRouting struct {
provided chan cid.Cid provided chan cid.Cid
} }
func (r *mockRouting) Provide(ctx context.Context, cid cid.Cid, recursive bool) error {
r.provided <- cid
return nil
}
func (r *mockRouting) FindProvidersAsync(ctx context.Context, cid cid.Cid, timeout int) <-chan pstore.PeerInfo {
return nil
}
func mockContentRouting() *mockRouting { func mockContentRouting() *mockRouting {
r := mockRouting{} r := mockRouting{}
r.provided = make(chan cid.Cid) r.provided = make(chan cid.Cid)
...@@ -68,13 +77,3 @@ func TestAnnouncement(t *testing.T) { ...@@ -68,13 +77,3 @@ func TestAnnouncement(t *testing.T) {
} }
} }
} }
func (r *mockRouting) Provide(ctx context.Context, cid cid.Cid, recursive bool) error {
r.provided <- cid
return nil
}
// Search for peers who are able to provide a given key
func (r *mockRouting) FindProvidersAsync(ctx context.Context, cid cid.Cid, timeout int) <-chan pstore.PeerInfo {
return nil
}
...@@ -52,7 +52,37 @@ func TestBasicOperation(t *testing.T) { ...@@ -52,7 +52,37 @@ func TestBasicOperation(t *testing.T) {
assertOrdered(cids, queue, t) assertOrdered(cids, queue, t)
} }
func TestInitialization(t *testing.T) { func TestSparseDatastore(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.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() ctx := context.Background()
defer ctx.Done() defer ctx.Done()
...@@ -63,7 +93,28 @@ func TestInitialization(t *testing.T) { ...@@ -63,7 +93,28 @@ func TestInitialization(t *testing.T) {
} }
cids := makeCids(10) 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 { for _, c := range cids {
queue.Enqueue(c) queue.Enqueue(c)
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论