test: ensure we always cancel active streaming notifications

This commit is contained in:
Olaoluwa Osuntokun 2018-04-24 20:34:56 -07:00
parent dbf7e4525a
commit 29a27bbc3a
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -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