mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-23 06:35:07 +01:00
Merge pull request #2306 from halseth/autopilot-unit-test-timeout-increase
autopilot: fix flaky Agent test
This commit is contained in:
commit
374bb3b0e7
1 changed files with 76 additions and 4 deletions
|
@ -143,9 +143,12 @@ func TestAgentChannelOpenSignal(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("unable to generate key: %v", err)
|
||||
}
|
||||
|
||||
quit := make(chan struct{})
|
||||
heuristic := &mockHeuristic{
|
||||
moreChansResps: make(chan moreChansResp),
|
||||
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
||||
quit: quit,
|
||||
}
|
||||
chanController := &mockChanController{
|
||||
openChanSignals: make(chan openChanIntent, 10),
|
||||
|
@ -189,6 +192,11 @@ func TestAgentChannelOpenSignal(t *testing.T) {
|
|||
}
|
||||
defer agent.Stop()
|
||||
|
||||
// We must defer the closing of quit after the defer agent.Stop(), to
|
||||
// make sure ConnectToPeer won't block preventing the agent from
|
||||
// exiting.
|
||||
defer close(quit)
|
||||
|
||||
// We'll send an initial "no" response to advance the agent past its
|
||||
// initial check.
|
||||
select {
|
||||
|
@ -268,9 +276,12 @@ func TestAgentChannelFailureSignal(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("unable to generate key: %v", err)
|
||||
}
|
||||
|
||||
quit := make(chan struct{})
|
||||
heuristic := &mockHeuristic{
|
||||
moreChansResps: make(chan moreChansResp),
|
||||
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
||||
quit: quit,
|
||||
}
|
||||
chanController := &mockFailingChanController{}
|
||||
memGraph, _, _ := newMemChanGraph()
|
||||
|
@ -313,6 +324,11 @@ func TestAgentChannelFailureSignal(t *testing.T) {
|
|||
}
|
||||
defer agent.Stop()
|
||||
|
||||
// We must defer the closing of quit after the defer agent.Stop(), to
|
||||
// make sure ConnectToPeer won't block preventing the agent from
|
||||
// exiting.
|
||||
defer close(quit)
|
||||
|
||||
// First ensure the agent will attempt to open a new channel. Return
|
||||
// that we need more channels, and have 5BTC to use.
|
||||
select {
|
||||
|
@ -371,9 +387,12 @@ func TestAgentChannelCloseSignal(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("unable to generate key: %v", err)
|
||||
}
|
||||
|
||||
quit := make(chan struct{})
|
||||
heuristic := &mockHeuristic{
|
||||
moreChansResps: make(chan moreChansResp),
|
||||
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
||||
quit: quit,
|
||||
}
|
||||
chanController := &mockChanController{
|
||||
openChanSignals: make(chan openChanIntent),
|
||||
|
@ -428,6 +447,11 @@ func TestAgentChannelCloseSignal(t *testing.T) {
|
|||
}
|
||||
defer agent.Stop()
|
||||
|
||||
// We must defer the closing of quit after the defer agent.Stop(), to
|
||||
// make sure ConnectToPeer won't block preventing the agent from
|
||||
// exiting.
|
||||
defer close(quit)
|
||||
|
||||
// We'll send an initial "no" response to advance the agent past its
|
||||
// initial check.
|
||||
select {
|
||||
|
@ -481,9 +505,12 @@ func TestAgentBalanceUpdate(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("unable to generate key: %v", err)
|
||||
}
|
||||
|
||||
quit := make(chan struct{})
|
||||
heuristic := &mockHeuristic{
|
||||
moreChansResps: make(chan moreChansResp),
|
||||
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
||||
quit: quit,
|
||||
}
|
||||
chanController := &mockChanController{
|
||||
openChanSignals: make(chan openChanIntent),
|
||||
|
@ -533,6 +560,11 @@ func TestAgentBalanceUpdate(t *testing.T) {
|
|||
}
|
||||
defer agent.Stop()
|
||||
|
||||
// We must defer the closing of quit after the defer agent.Stop(), to
|
||||
// make sure ConnectToPeer won't block preventing the agent from
|
||||
// exiting.
|
||||
defer close(quit)
|
||||
|
||||
// We'll send an initial "no" response to advance the agent past its
|
||||
// initial check.
|
||||
select {
|
||||
|
@ -591,9 +623,12 @@ func TestAgentImmediateAttach(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("unable to generate key: %v", err)
|
||||
}
|
||||
|
||||
quit := make(chan struct{})
|
||||
heuristic := &mockHeuristic{
|
||||
moreChansResps: make(chan moreChansResp),
|
||||
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
||||
quit: quit,
|
||||
}
|
||||
chanController := &mockChanController{
|
||||
openChanSignals: make(chan openChanIntent),
|
||||
|
@ -640,6 +675,11 @@ func TestAgentImmediateAttach(t *testing.T) {
|
|||
}
|
||||
defer agent.Stop()
|
||||
|
||||
// We must defer the closing of quit after the defer agent.Stop(), to
|
||||
// make sure ConnectToPeer won't block preventing the agent from
|
||||
// exiting.
|
||||
defer close(quit)
|
||||
|
||||
const numChans = 5
|
||||
|
||||
// The very first thing the agent should do is query the NeedMoreChans
|
||||
|
@ -726,9 +766,12 @@ func TestAgentPrivateChannels(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("unable to generate key: %v", err)
|
||||
}
|
||||
|
||||
quit := make(chan struct{})
|
||||
heuristic := &mockHeuristic{
|
||||
moreChansResps: make(chan moreChansResp),
|
||||
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
||||
quit: quit,
|
||||
}
|
||||
// The chanController should be initialized such that all of its open
|
||||
// channel requests are for private channels.
|
||||
|
@ -777,6 +820,11 @@ func TestAgentPrivateChannels(t *testing.T) {
|
|||
}
|
||||
defer agent.Stop()
|
||||
|
||||
// We must defer the closing of quit after the defer agent.Stop(), to
|
||||
// make sure ConnectToPeer won't block preventing the agent from
|
||||
// exiting.
|
||||
defer close(quit)
|
||||
|
||||
const numChans = 5
|
||||
|
||||
// The very first thing the agent should do is query the NeedMoreChans
|
||||
|
@ -850,9 +898,12 @@ func TestAgentPendingChannelState(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("unable to generate key: %v", err)
|
||||
}
|
||||
|
||||
quit := make(chan struct{})
|
||||
heuristic := &mockHeuristic{
|
||||
moreChansResps: make(chan moreChansResp),
|
||||
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
||||
quit: quit,
|
||||
}
|
||||
chanController := &mockChanController{
|
||||
openChanSignals: make(chan openChanIntent),
|
||||
|
@ -903,6 +954,11 @@ func TestAgentPendingChannelState(t *testing.T) {
|
|||
}
|
||||
defer agent.Stop()
|
||||
|
||||
// We must defer the closing of quit after the defer agent.Stop(), to
|
||||
// make sure ConnectToPeer won't block preventing the agent from
|
||||
// exiting.
|
||||
defer close(quit)
|
||||
|
||||
// Once again, we'll start by telling the agent as part of its first
|
||||
// query, that it needs more channels and has 3 BTC available for
|
||||
// attachment. We'll send over a response indicating that it should
|
||||
|
@ -1034,9 +1090,12 @@ func TestAgentPendingOpenChannel(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("unable to generate key: %v", err)
|
||||
}
|
||||
|
||||
quit := make(chan struct{})
|
||||
heuristic := &mockHeuristic{
|
||||
moreChansResps: make(chan moreChansResp),
|
||||
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
||||
quit: quit,
|
||||
}
|
||||
chanController := &mockChanController{
|
||||
openChanSignals: make(chan openChanIntent),
|
||||
|
@ -1076,6 +1135,11 @@ func TestAgentPendingOpenChannel(t *testing.T) {
|
|||
}
|
||||
defer agent.Stop()
|
||||
|
||||
// We must defer the closing of quit after the defer agent.Stop(), to
|
||||
// make sure ConnectToPeer won't block preventing the agent from
|
||||
// exiting.
|
||||
defer close(quit)
|
||||
|
||||
// We'll send an initial "no" response to advance the agent past its
|
||||
// initial check.
|
||||
select {
|
||||
|
@ -1119,9 +1183,12 @@ func TestAgentOnNodeUpdates(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("unable to generate key: %v", err)
|
||||
}
|
||||
|
||||
quit := make(chan struct{})
|
||||
heuristic := &mockHeuristic{
|
||||
moreChansResps: make(chan moreChansResp),
|
||||
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
||||
quit: quit,
|
||||
}
|
||||
chanController := &mockChanController{
|
||||
openChanSignals: make(chan openChanIntent),
|
||||
|
@ -1161,6 +1228,11 @@ func TestAgentOnNodeUpdates(t *testing.T) {
|
|||
}
|
||||
defer agent.Stop()
|
||||
|
||||
// We must defer the closing of quit after the defer agent.Stop(), to
|
||||
// make sure ConnectToPeer won't block preventing the agent from
|
||||
// exiting.
|
||||
defer close(quit)
|
||||
|
||||
// We'll send an initial "yes" response to advance the agent past its
|
||||
// initial check. This will cause it to try to get directives from an
|
||||
// empty graph.
|
||||
|
@ -1224,9 +1296,12 @@ func TestAgentSkipPendingConns(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("unable to generate key: %v", err)
|
||||
}
|
||||
|
||||
quit := make(chan struct{})
|
||||
heuristic := &mockHeuristic{
|
||||
moreChansResps: make(chan moreChansResp),
|
||||
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
||||
quit: quit,
|
||||
}
|
||||
chanController := &mockChanController{
|
||||
openChanSignals: make(chan openChanIntent),
|
||||
|
@ -1237,7 +1312,6 @@ func TestAgentSkipPendingConns(t *testing.T) {
|
|||
const walletBalance = btcutil.SatoshiPerBitcoin * 6
|
||||
|
||||
connect := make(chan chan error)
|
||||
quit := make(chan struct{})
|
||||
|
||||
// With the dependencies we created, we can now create the initial
|
||||
// agent itself.
|
||||
|
@ -1379,9 +1453,7 @@ func TestAgentSkipPendingConns(t *testing.T) {
|
|||
t.Fatalf("agent did not receive connection timeout")
|
||||
}
|
||||
|
||||
// Signal the agent to try again, now that there are no pending conns.
|
||||
agent.OnNodeUpdates()
|
||||
|
||||
// The agent will now retry since the last connection attempt failed.
|
||||
// The heuristic again informs the agent that we need more channels.
|
||||
select {
|
||||
case heuristic.moreChansResps <- moreChansResp{
|
||||
|
|
Loading…
Add table
Reference in a new issue