Merge pull request #2306 from halseth/autopilot-unit-test-timeout-increase

autopilot: fix flaky Agent test
This commit is contained in:
Olaoluwa Osuntokun 2018-12-11 16:02:01 -08:00 committed by GitHub
commit 374bb3b0e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -143,9 +143,12 @@ func TestAgentChannelOpenSignal(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("unable to generate key: %v", err) t.Fatalf("unable to generate key: %v", err)
} }
quit := make(chan struct{})
heuristic := &mockHeuristic{ heuristic := &mockHeuristic{
moreChansResps: make(chan moreChansResp), moreChansResps: make(chan moreChansResp),
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective), nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
quit: quit,
} }
chanController := &mockChanController{ chanController := &mockChanController{
openChanSignals: make(chan openChanIntent, 10), openChanSignals: make(chan openChanIntent, 10),
@ -189,6 +192,11 @@ func TestAgentChannelOpenSignal(t *testing.T) {
} }
defer agent.Stop() 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 // We'll send an initial "no" response to advance the agent past its
// initial check. // initial check.
select { select {
@ -268,9 +276,12 @@ func TestAgentChannelFailureSignal(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("unable to generate key: %v", err) t.Fatalf("unable to generate key: %v", err)
} }
quit := make(chan struct{})
heuristic := &mockHeuristic{ heuristic := &mockHeuristic{
moreChansResps: make(chan moreChansResp), moreChansResps: make(chan moreChansResp),
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective), nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
quit: quit,
} }
chanController := &mockFailingChanController{} chanController := &mockFailingChanController{}
memGraph, _, _ := newMemChanGraph() memGraph, _, _ := newMemChanGraph()
@ -313,6 +324,11 @@ func TestAgentChannelFailureSignal(t *testing.T) {
} }
defer agent.Stop() 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 // First ensure the agent will attempt to open a new channel. Return
// that we need more channels, and have 5BTC to use. // that we need more channels, and have 5BTC to use.
select { select {
@ -371,9 +387,12 @@ func TestAgentChannelCloseSignal(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("unable to generate key: %v", err) t.Fatalf("unable to generate key: %v", err)
} }
quit := make(chan struct{})
heuristic := &mockHeuristic{ heuristic := &mockHeuristic{
moreChansResps: make(chan moreChansResp), moreChansResps: make(chan moreChansResp),
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective), nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
quit: quit,
} }
chanController := &mockChanController{ chanController := &mockChanController{
openChanSignals: make(chan openChanIntent), openChanSignals: make(chan openChanIntent),
@ -428,6 +447,11 @@ func TestAgentChannelCloseSignal(t *testing.T) {
} }
defer agent.Stop() 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 // We'll send an initial "no" response to advance the agent past its
// initial check. // initial check.
select { select {
@ -481,9 +505,12 @@ func TestAgentBalanceUpdate(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("unable to generate key: %v", err) t.Fatalf("unable to generate key: %v", err)
} }
quit := make(chan struct{})
heuristic := &mockHeuristic{ heuristic := &mockHeuristic{
moreChansResps: make(chan moreChansResp), moreChansResps: make(chan moreChansResp),
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective), nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
quit: quit,
} }
chanController := &mockChanController{ chanController := &mockChanController{
openChanSignals: make(chan openChanIntent), openChanSignals: make(chan openChanIntent),
@ -533,6 +560,11 @@ func TestAgentBalanceUpdate(t *testing.T) {
} }
defer agent.Stop() 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 // We'll send an initial "no" response to advance the agent past its
// initial check. // initial check.
select { select {
@ -591,9 +623,12 @@ func TestAgentImmediateAttach(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("unable to generate key: %v", err) t.Fatalf("unable to generate key: %v", err)
} }
quit := make(chan struct{})
heuristic := &mockHeuristic{ heuristic := &mockHeuristic{
moreChansResps: make(chan moreChansResp), moreChansResps: make(chan moreChansResp),
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective), nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
quit: quit,
} }
chanController := &mockChanController{ chanController := &mockChanController{
openChanSignals: make(chan openChanIntent), openChanSignals: make(chan openChanIntent),
@ -640,6 +675,11 @@ func TestAgentImmediateAttach(t *testing.T) {
} }
defer agent.Stop() 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 const numChans = 5
// The very first thing the agent should do is query the NeedMoreChans // The very first thing the agent should do is query the NeedMoreChans
@ -726,9 +766,12 @@ func TestAgentPrivateChannels(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("unable to generate key: %v", err) t.Fatalf("unable to generate key: %v", err)
} }
quit := make(chan struct{})
heuristic := &mockHeuristic{ heuristic := &mockHeuristic{
moreChansResps: make(chan moreChansResp), moreChansResps: make(chan moreChansResp),
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective), nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
quit: quit,
} }
// The chanController should be initialized such that all of its open // The chanController should be initialized such that all of its open
// channel requests are for private channels. // channel requests are for private channels.
@ -777,6 +820,11 @@ func TestAgentPrivateChannels(t *testing.T) {
} }
defer agent.Stop() 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 const numChans = 5
// The very first thing the agent should do is query the NeedMoreChans // The very first thing the agent should do is query the NeedMoreChans
@ -850,9 +898,12 @@ func TestAgentPendingChannelState(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("unable to generate key: %v", err) t.Fatalf("unable to generate key: %v", err)
} }
quit := make(chan struct{})
heuristic := &mockHeuristic{ heuristic := &mockHeuristic{
moreChansResps: make(chan moreChansResp), moreChansResps: make(chan moreChansResp),
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective), nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
quit: quit,
} }
chanController := &mockChanController{ chanController := &mockChanController{
openChanSignals: make(chan openChanIntent), openChanSignals: make(chan openChanIntent),
@ -903,6 +954,11 @@ func TestAgentPendingChannelState(t *testing.T) {
} }
defer agent.Stop() 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 // 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 // query, that it needs more channels and has 3 BTC available for
// attachment. We'll send over a response indicating that it should // attachment. We'll send over a response indicating that it should
@ -1034,9 +1090,12 @@ func TestAgentPendingOpenChannel(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("unable to generate key: %v", err) t.Fatalf("unable to generate key: %v", err)
} }
quit := make(chan struct{})
heuristic := &mockHeuristic{ heuristic := &mockHeuristic{
moreChansResps: make(chan moreChansResp), moreChansResps: make(chan moreChansResp),
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective), nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
quit: quit,
} }
chanController := &mockChanController{ chanController := &mockChanController{
openChanSignals: make(chan openChanIntent), openChanSignals: make(chan openChanIntent),
@ -1076,6 +1135,11 @@ func TestAgentPendingOpenChannel(t *testing.T) {
} }
defer agent.Stop() 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 // We'll send an initial "no" response to advance the agent past its
// initial check. // initial check.
select { select {
@ -1119,9 +1183,12 @@ func TestAgentOnNodeUpdates(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("unable to generate key: %v", err) t.Fatalf("unable to generate key: %v", err)
} }
quit := make(chan struct{})
heuristic := &mockHeuristic{ heuristic := &mockHeuristic{
moreChansResps: make(chan moreChansResp), moreChansResps: make(chan moreChansResp),
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective), nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
quit: quit,
} }
chanController := &mockChanController{ chanController := &mockChanController{
openChanSignals: make(chan openChanIntent), openChanSignals: make(chan openChanIntent),
@ -1161,6 +1228,11 @@ func TestAgentOnNodeUpdates(t *testing.T) {
} }
defer agent.Stop() 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 // 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 // initial check. This will cause it to try to get directives from an
// empty graph. // empty graph.
@ -1224,9 +1296,12 @@ func TestAgentSkipPendingConns(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("unable to generate key: %v", err) t.Fatalf("unable to generate key: %v", err)
} }
quit := make(chan struct{})
heuristic := &mockHeuristic{ heuristic := &mockHeuristic{
moreChansResps: make(chan moreChansResp), moreChansResps: make(chan moreChansResp),
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective), nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
quit: quit,
} }
chanController := &mockChanController{ chanController := &mockChanController{
openChanSignals: make(chan openChanIntent), openChanSignals: make(chan openChanIntent),
@ -1237,7 +1312,6 @@ func TestAgentSkipPendingConns(t *testing.T) {
const walletBalance = btcutil.SatoshiPerBitcoin * 6 const walletBalance = btcutil.SatoshiPerBitcoin * 6
connect := make(chan chan error) connect := make(chan chan error)
quit := make(chan struct{})
// With the dependencies we created, we can now create the initial // With the dependencies we created, we can now create the initial
// agent itself. // agent itself.
@ -1379,9 +1453,7 @@ func TestAgentSkipPendingConns(t *testing.T) {
t.Fatalf("agent did not receive connection timeout") t.Fatalf("agent did not receive connection timeout")
} }
// Signal the agent to try again, now that there are no pending conns. // The agent will now retry since the last connection attempt failed.
agent.OnNodeUpdates()
// The heuristic again informs the agent that we need more channels. // The heuristic again informs the agent that we need more channels.
select { select {
case heuristic.moreChansResps <- moreChansResp{ case heuristic.moreChansResps <- moreChansResp{