From 7fcafb66152f5ac0f49e82899932432d0e445a55 Mon Sep 17 00:00:00 2001 From: Erik Ingenito Date: Fri, 15 Mar 2019 16:36:43 -0700 Subject: [PATCH] Gofmt License: MIT Signed-off-by: Erik Ingenito --- provider/provider.go | 2 +- provider/provider_test.go | 20 ++++++++++---------- provider/queue.go | 31 ++++++++++++++----------------- provider/queue_test.go | 2 +- 4 files changed, 26 insertions(+), 29 deletions(-) diff --git a/provider/provider.go b/provider/provider.go index 7e149f777..a5093d65b 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -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 diff --git a/provider/provider_test.go b/provider/provider_test.go index 95282e38a..7836f04ce 100644 --- a/provider/provider_test.go +++ b/provider/provider_test.go @@ -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 -} \ No newline at end of file +} diff --git a/provider/queue.go b/provider/queue.go index 3f7115f68..b5b7ba709 100644 --- a/provider/queue.go +++ b/provider/queue.go @@ -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(): } } diff --git a/provider/queue_test.go b/provider/queue_test.go index 2ac2de288..0dd3bab09 100644 --- a/provider/queue_test.go +++ b/provider/queue_test.go @@ -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) }