autopilot/agent: add attachment directive goroutine to wait group

This commit is contained in:
Johan T. Halseth 2018-12-06 14:24:15 +01:00
parent 35f4ec84d1
commit 86e6d230f2
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
2 changed files with 22 additions and 3 deletions

@ -545,7 +545,10 @@ func (a *Agent) controller() {
}
pendingConns[nodeID] = struct{}{}
a.wg.Add(1)
go func(directive AttachmentDirective) {
defer a.wg.Done()
// We'll start out by attempting to connect to
// the peer in order to begin the funding
// workflow.

@ -1231,6 +1231,7 @@ 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.
@ -1243,9 +1244,19 @@ func TestAgentSkipPendingConns(t *testing.T) {
},
ConnectToPeer: func(*btcec.PublicKey, []net.Addr) (bool, error) {
errChan := make(chan error)
connect <- errChan
err := <-errChan
select {
case connect <- errChan:
case <-quit:
return false, errors.New("quit")
}
select {
case err := <-errChan:
return false, err
case <-quit:
return false, errors.New("quit")
}
},
DisconnectPeer: func(*btcec.PublicKey) error {
return nil
@ -1272,6 +1283,11 @@ func TestAgentSkipPendingConns(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 the
// graph.