@cryptotaxi247 / kubo / commits / c2b21e473

routing/mock test: kill leaked goroutine

Juan Batiz-Benet committed Dec 22, 2014 at 15:11 UTC c2b21e473dcf9d3a7d9f26755cdb9908bb25f339
1 file changed +13
routing/mock/mockrouting_test.go
+13
@@ -96,10 +96,23 @@ func TestCanceledContext(t *testing.T) {
96 rs := NewServer()
97 k := u.Key("hello")
98
99 + // avoid leaking goroutine, without using the context to signal
100 + // (we want the goroutine to keep trying to publish on a
101 + // cancelled context until we've tested it doesnt do anything.)
102 + done := make(chan struct{})
103 + defer func() { done <- struct{}{} }()
104 +
105 t.Log("async'ly announce infinite stream of providers for key")
106 i := 0
107 go func() { // infinite stream
108 for {
109 + select {
110 + case <-done:
111 + t.Log("exiting async worker")
112 + return
113 + default:
114 + }
115 +
116 pi := peer.PeerInfo{ID: peer.ID(i)}
117 err := rs.Client(pi).Provide(context.Background(), k)
118 if err != nil {