Skip to content

Commit

Permalink
itest: Fix connection test
Browse files Browse the repository at this point in the history
Now that disconnection takes longer, this test also needs fixing.
  • Loading branch information
matheusd committed Dec 22, 2022
1 parent ce4fe1d commit 12067f4
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lntest/itest/dcrlnd_maxio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/decred/dcrd/dcrutil/v4"
"github.com/decred/dcrlnd/lnrpc"
"github.com/decred/dcrlnd/lntest"
"github.com/stretchr/testify/require"
)

// testAddInvoiceMaxInboundAmt tests whether trying to add an invoice fails
Expand Down Expand Up @@ -118,13 +119,23 @@ func testAddInvoiceMaxInboundAmt(net *lntest.NetworkHarness, t *harnessTest) {
}
}

peerReq := &lnrpc.PeerEventSubscription{}
carolPeerClient, err := carol.SubscribePeerEvents(ctxb, peerReq)
require.NoError(t.t, err)

// Disconnect the nodes from one another. While their channel remains open,
// carol cannot receive payments (since bob is offline from her POV).
err = net.DisconnectNodes(ctxb, carol, net.Bob)
if err != nil {
t.Fatalf("unable to disconnect carol and bob: %v", err)
}

// Wait to receive the PEER_OFFLINE event before trying to create the
// invoice.
peerEvent, err := carolPeerClient.Recv()
require.NoError(t.t, err)
require.Equal(t.t, lnrpc.PeerEvent_PEER_OFFLINE, peerEvent.GetType())

// Now trying to add an invoice with an offline peer should fail.
err = addInvoice(0, false)
if err == nil {
Expand Down Expand Up @@ -350,6 +361,10 @@ func testSendPaymentMaxOutboundAmt(net *lntest.NetworkHarness, t *harnessTest) {
}
}

peerReq := &lnrpc.PeerEventSubscription{}
carolPeerClient, err := carol.SubscribePeerEvents(ctxb, peerReq)
require.NoError(t.t, err)

// Disconnect the nodes from one another. While their channel remains
// open, carol cannot send payments (since bob is offline from her
// POV).
Expand All @@ -358,6 +373,12 @@ func testSendPaymentMaxOutboundAmt(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("unable to disconnect carol and bob: %v", err)
}

// Wait to receive the PEER_OFFLINE event before trying to create the
// invoice.
peerEvent, err := carolPeerClient.Recv()
require.NoError(t.t, err)
require.Equal(t.t, lnrpc.PeerEvent_PEER_OFFLINE, peerEvent.GetType())

// Now trying to send a payment with an offline peer should fail.
err = sendPayment(1)
if err == nil {
Expand Down

0 comments on commit 12067f4

Please sign in to comment.