rpctest: Prevent race during teardown.

This commit is contained in:
Dave Collins 2016-12-07 10:31:02 -06:00
parent 53edcec224
commit cb05e9b9cf
No known key found for this signature in database
GPG key ID: B8904D9D9C93D1F2
2 changed files with 16 additions and 5 deletions

View file

@ -255,12 +255,11 @@ func (h *Harness) SetUp(createTestChain bool, numMatureOutputs uint32) error {
return nil
}
// TearDown stops the running rpc test instance. All created processes are
// tearDown stops the running rpc test instance. All created processes are
// killed, and temporary directories removed.
//
// NOTE: This method and SetUp should always be called from the same goroutine
// as they are not concurrent safe.
func (h *Harness) TearDown() error {
// This function MUST be called with the harness state mutex held (for writes).
func (h *Harness) tearDown() error {
if h.Node != nil {
h.Node.Shutdown()
}
@ -278,6 +277,18 @@ func (h *Harness) TearDown() error {
return nil
}
// TearDown stops the running rpc test instance. All created processes are
// killed, and temporary directories removed.
//
// NOTE: This method and SetUp should always be called from the same goroutine
// as they are not concurrent safe.
func (h *Harness) TearDown() error {
harnessStateMtx.Lock()
defer harnessStateMtx.Unlock()
return h.tearDown()
}
// connectRPCClient attempts to establish an RPC connection to the created btcd
// process belonging to this Harness instance. If the initial connection
// attempt fails, this function will retry h.maxConnRetries times, backing off

View file

@ -140,7 +140,7 @@ func TearDownAll() error {
defer harnessStateMtx.Unlock()
for _, harness := range testInstances {
if err := harness.TearDown(); err != nil {
if err := harness.tearDown(); err != nil {
return err
}
}