Skip to content

Commit

Permalink
routing/mock test: kill leaked goroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
jbenet committed Dec 22, 2014
1 parent 861462f commit 4b15204
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions routing/mock/mockrouting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,23 @@ func TestCanceledContext(t *testing.T) {
rs := NewServer()
k := u.Key("hello")

// avoid leaking goroutine, without using the context to signal
// (we want the goroutine to keep trying to publish on a
// cancelled context until we've tested it doesnt do anything.)
done := make(chan struct{})
defer func() { done <- struct{}{} }()

t.Log("async'ly announce infinite stream of providers for key")
i := 0
go func() { // infinite stream
for {
select {
case <-done:
t.Log("exiting async worker")
return
default:
}

pi := peer.PeerInfo{ID: peer.ID(i)}
err := rs.Client(pi).Provide(context.Background(), k)
if err != nil {
Expand Down

3 comments on commit 4b15204

@jbenet
Copy link
Member Author

@jbenet jbenet commented on 4b15204 Dec 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @whyrusleeping @maybebtc LGTU?

@whyrusleeping
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, looks good to me

@btc
Copy link
Contributor

@btc btc commented on 4b15204 Dec 23, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Please sign in to comment.