Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit da9d6e3

Browse files
committed
add simple FindProvs support
1 parent 190b506 commit da9d6e3

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

shell.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,17 +390,22 @@ func (s *Shell) FindProvs(ctx context.Context, cid string) (<-chan pstore.PeerIn
390390
outchan := make(chan pstore.PeerInfo, 4)
391391

392392
go func() {
393+
defer cancel()
394+
393395
var n notif.QueryEvent
394396
scanner := bufio.NewScanner(resp.Output)
395397
for scanner.Scan() {
396398
json.Unmarshal(scanner.Bytes(), &n)
397399
if n.Type == notif.Provider {
398400
for _, p := range n.Responses {
399-
outchan <- *p
401+
select {
402+
case outchan <- *p:
403+
case <-ctx.Done():
404+
return
405+
}
400406
}
401407
}
402408
}
403-
cancel()
404409
}()
405410

406411
go func() {

shell_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package shell
22

33
import (
44
"bytes"
5+
"context"
56
"crypto/md5"
67
"fmt"
78
"io"
@@ -212,3 +213,18 @@ func TestObjectStat(t *testing.T) {
212213
is.Equal(stat.LinksSize, 3)
213214
is.Equal(stat.CumulativeSize, 1688)
214215
}
216+
217+
func TestFindProvs(t *testing.T) {
218+
is := is.New(t)
219+
s := NewShell(shellUrl)
220+
ctx, cancel := context.WithCancel(context.Background())
221+
defer cancel()
222+
223+
c, err := s.FindProvs(ctx, "Qme1g4e3m2SmdiSGGU3vSWmUStwUjc5oECnEriaK9Xa1HU")
224+
is.Nil(err)
225+
226+
p := <-c
227+
t.Logf("prov: %s", p)
228+
is.NotNil(p)
229+
is.NotNil(p.ID)
230+
}

0 commit comments

Comments
 (0)