From 032f908f4adaaf2c73a90b38948ceb3431899998 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Tue, 25 Sep 2018 15:24:42 -0700 Subject: [PATCH] core: MockProvider and MockProvisioner can't lock in Stop The only reasonable usage of these methods is for them to run concurrently with other methods, so we mustn't hold a lock to do this work. For tests that deal with stopping, it's the test's own responsibility to deal with any concurrency issues that arise from their StopFns running concurrently with other mock functions. --- terraform/provider_mock.go | 6 ++++-- terraform/provisioner_mock.go | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/terraform/provider_mock.go b/terraform/provider_mock.go index b38478281..b3e138b13 100644 --- a/terraform/provider_mock.go +++ b/terraform/provider_mock.go @@ -226,8 +226,10 @@ func (p *MockProvider) Configure(r providers.ConfigureRequest) providers.Configu } func (p *MockProvider) Stop() error { - p.Lock() - defer p.Unlock() + // We intentionally don't lock in this one because the whole point of this + // method is to be called concurrently with another operation that can + // be cancelled. The provider itself is responsible for handling + // any concurrency concerns in this case. p.StopCalled = true if p.StopFn != nil { diff --git a/terraform/provisioner_mock.go b/terraform/provisioner_mock.go index 1a5736c8c..f0682e4f0 100644 --- a/terraform/provisioner_mock.go +++ b/terraform/provisioner_mock.go @@ -119,8 +119,10 @@ func (p *MockProvisioner) ProvisionResource(r provisioners.ProvisionResourceRequ } func (p *MockProvisioner) Stop() error { - p.Lock() - defer p.Unlock() + // We intentionally don't lock in this one because the whole point of this + // method is to be called concurrently with another operation that can + // be cancelled. The provisioner itself is responsible for handling + // any concurrency concerns in this case. p.StopCalled = true if p.StopFn != nil {