mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-26 04:47:45 +08:00
Gofmt
License: MIT Signed-off-by: Erik Ingenito <erik@carbonfive.com>
This commit is contained in:
parent
1595253b7b
commit
7fcafb6615
@ -11,7 +11,7 @@ import (
|
||||
routing "github.com/libp2p/go-libp2p-routing"
|
||||
)
|
||||
|
||||
var log = logging.Logger("provider")
|
||||
var log = logging.Logger("provider")
|
||||
|
||||
const provideOutgoingWorkerLimit = 8
|
||||
|
||||
|
||||
@ -6,11 +6,11 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
blocksutil "github.com/ipfs/go-ipfs-blocksutil"
|
||||
cid "github.com/ipfs/go-cid"
|
||||
datastore "github.com/ipfs/go-datastore"
|
||||
pstore "github.com/libp2p/go-libp2p-peerstore"
|
||||
sync "github.com/ipfs/go-datastore/sync"
|
||||
blocksutil "github.com/ipfs/go-ipfs-blocksutil"
|
||||
pstore "github.com/libp2p/go-libp2p-peerstore"
|
||||
)
|
||||
|
||||
var blockGenerator = blocksutil.NewBlockGenerator()
|
||||
@ -58,13 +58,13 @@ func TestAnnouncement(t *testing.T) {
|
||||
|
||||
for cids.Len() > 0 {
|
||||
select {
|
||||
case cp := <-r.provided:
|
||||
if !cids.Has(cp) {
|
||||
t.Fatal("Wrong CID provided")
|
||||
}
|
||||
cids.Remove(cp)
|
||||
case <-time.After(time.Second * 5):
|
||||
t.Fatal("Timeout waiting for cids to be provided.")
|
||||
case cp := <-r.provided:
|
||||
if !cids.Has(cp) {
|
||||
t.Fatal("Wrong CID provided")
|
||||
}
|
||||
cids.Remove(cp)
|
||||
case <-time.After(time.Second * 5):
|
||||
t.Fatal("Timeout waiting for cids to be provided.")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -77,4 +77,4 @@ func (r *mockRouting) Provide(ctx context.Context, cid cid.Cid, recursive bool)
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,14 +19,11 @@ import (
|
||||
type Queue struct {
|
||||
// used to differentiate queues in datastore
|
||||
// e.g. provider vs reprovider
|
||||
name string
|
||||
ctx context.Context
|
||||
|
||||
tail uint64
|
||||
head uint64
|
||||
|
||||
ds datastore.Datastore // Must be threadsafe
|
||||
|
||||
name string
|
||||
ctx context.Context
|
||||
tail uint64
|
||||
head uint64
|
||||
ds datastore.Datastore // Must be threadsafe
|
||||
dequeue chan cid.Cid
|
||||
enqueue chan cid.Cid
|
||||
}
|
||||
@ -39,13 +36,13 @@ func NewQueue(ctx context.Context, name string, ds datastore.Datastore) (*Queue,
|
||||
return nil, err
|
||||
}
|
||||
q := &Queue{
|
||||
name: name,
|
||||
ctx: ctx,
|
||||
head: head,
|
||||
tail: tail,
|
||||
ds: namespaced,
|
||||
dequeue: make(chan cid.Cid),
|
||||
enqueue: make(chan cid.Cid),
|
||||
name: name,
|
||||
ctx: ctx,
|
||||
head: head,
|
||||
tail: tail,
|
||||
ds: namespaced,
|
||||
dequeue: make(chan cid.Cid),
|
||||
enqueue: make(chan cid.Cid),
|
||||
}
|
||||
q.work()
|
||||
return q, nil
|
||||
@ -54,8 +51,8 @@ func NewQueue(ctx context.Context, name string, ds datastore.Datastore) (*Queue,
|
||||
// Enqueue puts a cid in the queue
|
||||
func (q *Queue) Enqueue(cid cid.Cid) {
|
||||
select {
|
||||
case q.enqueue <- cid:
|
||||
case <-q.ctx.Done():
|
||||
case q.enqueue <- cid:
|
||||
case <-q.ctx.Done():
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ func makeCids(n int) []cid.Cid {
|
||||
func assertOrdered(cids []cid.Cid, q *Queue, t *testing.T) {
|
||||
for _, c := range cids {
|
||||
select {
|
||||
case dequeued := <- q.dequeue:
|
||||
case dequeued := <-q.dequeue:
|
||||
if c != dequeued {
|
||||
t.Fatalf("Error in ordering of CIDs retrieved from queue. Expected: %s, got: %s", c, dequeued)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user