Merge pull request #486 from cfromknecht/invoice-itest-cancel

lnd_test: invoice subscription cancel lingering goroutine
This commit is contained in:
Olaoluwa Osuntokun 2017-12-17 18:42:36 -08:00 committed by GitHub
commit e0c292d960
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 2 deletions

View File

@ -2258,9 +2258,17 @@ func testInvoiceSubscriptions(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("unable to subscribe to bob's invoice updates: %v", err) t.Fatalf("unable to subscribe to bob's invoice updates: %v", err)
} }
quit := make(chan struct{})
updateSent := make(chan struct{}) updateSent := make(chan struct{})
go func() { go func() {
invoiceUpdate, err := bobInvoiceSubscription.Recv() invoiceUpdate, err := bobInvoiceSubscription.Recv()
select {
case <-quit:
// Received cancellation
return
default:
}
if err != nil { if err != nil {
t.Fatalf("unable to recv invoice update: %v", err) t.Fatalf("unable to recv invoice update: %v", err)
} }
@ -2289,6 +2297,7 @@ func testInvoiceSubscriptions(net *lntest.NetworkHarness, t *harnessTest) {
if err != nil { if err != nil {
// TODO(roasbeef): will need to make num blocks to advertise a // TODO(roasbeef): will need to make num blocks to advertise a
// node param // node param
close(quit)
t.Fatalf("channel not seen by alice before timeout: %v", err) t.Fatalf("channel not seen by alice before timeout: %v", err)
} }
@ -2300,15 +2309,18 @@ func testInvoiceSubscriptions(net *lntest.NetworkHarness, t *harnessTest) {
ctxt, _ = context.WithTimeout(ctxb, timeout) ctxt, _ = context.WithTimeout(ctxb, timeout)
resp, err := net.Alice.SendPaymentSync(ctxt, sendReq) resp, err := net.Alice.SendPaymentSync(ctxt, sendReq)
if err != nil { if err != nil {
close(quit)
t.Fatalf("unable to send payment: %v", err) t.Fatalf("unable to send payment: %v", err)
} }
if resp.PaymentError != "" { if resp.PaymentError != "" {
close(quit)
t.Fatalf("error when attempting recv: %v", resp.PaymentError) t.Fatalf("error when attempting recv: %v", resp.PaymentError)
} }
select { select {
case <-time.After(time.Second * 5): case <-time.After(time.Second * 10):
t.Fatalf("update not sent after 5 seconds") close(quit)
t.Fatalf("update not sent after 10 seconds")
case <-updateSent: // Fall through on success case <-updateSent: // Fall through on success
} }