autopilot/agent: add attachment directive goroutine to wait group
This commit is contained in:
parent
35f4ec84d1
commit
86e6d230f2
@ -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
|
||||
return false, err
|
||||
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user