From c2b21e473dcf9d3a7d9f26755cdb9908bb25f339 Mon Sep 17 00:00:00 2001 From: Juan Batiz-Benet Date: Mon, 22 Dec 2014 15:11:17 -0800 Subject: [PATCH] routing/mock test: kill leaked goroutine --- routing/mock/mockrouting_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/routing/mock/mockrouting_test.go b/routing/mock/mockrouting_test.go index 64540a3bc..739edbc63 100644 --- a/routing/mock/mockrouting_test.go +++ b/routing/mock/mockrouting_test.go @@ -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 {