Introduce locking on the hook mocks to avoid data race failures (#1505)

Signed-off-by: James Humphries <james@james-humphries.co.uk>
This commit is contained in:
James Humphries 2024-04-18 08:31:11 +01:00 committed by GitHub
parent f38b805357
commit 0c8991fca5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -292,18 +292,27 @@ func (h *MockHook) PostImportState(addr addrs.AbsResourceInstance, imported []pr
} }
func (h *MockHook) PrePlanImport(addr addrs.AbsResourceInstance, importID string) (HookAction, error) { func (h *MockHook) PrePlanImport(addr addrs.AbsResourceInstance, importID string) (HookAction, error) {
h.Lock()
defer h.Unlock()
h.PrePlanImportCalled = true h.PrePlanImportCalled = true
h.PrePlanImportAddr = addr h.PrePlanImportAddr = addr
return h.PrePlanImportReturn, h.PrePlanImportError return h.PrePlanImportReturn, h.PrePlanImportError
} }
func (h *MockHook) PostPlanImport(addr addrs.AbsResourceInstance, imported []providers.ImportedResource) (HookAction, error) { func (h *MockHook) PostPlanImport(addr addrs.AbsResourceInstance, imported []providers.ImportedResource) (HookAction, error) {
h.Lock()
defer h.Unlock()
h.PostPlanImportCalled = true h.PostPlanImportCalled = true
h.PostPlanImportAddr = addr h.PostPlanImportAddr = addr
return h.PostPlanImportReturn, h.PostPlanImportError return h.PostPlanImportReturn, h.PostPlanImportError
} }
func (h *MockHook) PreApplyImport(addr addrs.AbsResourceInstance, importing plans.ImportingSrc) (HookAction, error) { func (h *MockHook) PreApplyImport(addr addrs.AbsResourceInstance, importing plans.ImportingSrc) (HookAction, error) {
h.Lock()
defer h.Unlock()
h.PreApplyImportCalled = true h.PreApplyImportCalled = true
h.PreApplyImportAddr = addr h.PreApplyImportAddr = addr
return h.PreApplyImportReturn, h.PreApplyImportError return h.PreApplyImportReturn, h.PreApplyImportError