From 29a27bbc3ab634177b6e58ae6fcedc087a78e9c4 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 24 Apr 2018 20:34:56 -0700 Subject: [PATCH] test: ensure we always cancel active streaming notifications --- lnd_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lnd_test.go b/lnd_test.go index 240d99ce..47c07aa8 100644 --- a/lnd_test.go +++ b/lnd_test.go @@ -4302,10 +4302,12 @@ func testInvoiceSubscriptions(net *lntest.NetworkHarness, t *harnessTest) { // Create a new invoice subscription client for Bob, the notification // should be dispatched shortly below. req := &lnrpc.InvoiceSubscription{} - bobInvoiceSubscription, err := net.Bob.SubscribeInvoices(ctxb, req) + ctx, cancelFunc := context.WithCancel(context.Background()) + bobInvoiceSubscription, err := net.Bob.SubscribeInvoices(ctx, req) if err != nil { t.Fatalf("unable to subscribe to bob's invoice updates: %v", err) } + defer cancelFunc() quit := make(chan struct{}) updateSent := make(chan struct{}) @@ -5986,7 +5988,8 @@ func subscribeGraphNotifications(t *harnessTest, ctxb context.Context, // We'll first start by establishing a notification client which will // send us notifications upon detected changes in the channel graph. req := &lnrpc.GraphTopologySubscription{} - topologyClient, err := node.SubscribeChannelGraph(ctxb, req) + ctx, cancelFunc := context.WithCancel(context.Background()) + topologyClient, err := node.SubscribeChannelGraph(ctx, req) if err != nil { t.Fatalf("unable to create topology client: %v", err) } @@ -5997,6 +6000,8 @@ func subscribeGraphNotifications(t *harnessTest, ctxb context.Context, graphUpdates := make(chan *lnrpc.GraphTopologyUpdate, 20) go func() { for { + defer cancelFunc() + select { case <-quit: return