Skip to content

Commit

Permalink
Gofmt
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 15, 2019
1 parent 1595253 commit 25474eb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 29 deletions.
2 changes: 1 addition & 1 deletion provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 10 additions & 10 deletions provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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.")
}
}
}
Expand All @@ -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
}
}
31 changes: 14 additions & 17 deletions provider/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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():
}
}

Expand Down
2 changes: 1 addition & 1 deletion provider/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 25474eb

Please sign in to comment.