mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-29 10:21:01 -06:00
Merge pull request #12812 from hashicorp/jbardin/hook-ui-race
fix race in hook ui PreApply test
This commit is contained in:
commit
434e78158a
@ -39,6 +39,8 @@ type uiResourceState struct {
|
||||
Start time.Time
|
||||
|
||||
DoneCh chan struct{} // To be used for cancellation
|
||||
|
||||
done chan struct{} // used to coordinate tests
|
||||
}
|
||||
|
||||
// uiResourceOp is an enum for operations on a resource
|
||||
@ -146,6 +148,7 @@ func (h *UiHook) PreApply(
|
||||
Op: op,
|
||||
Start: time.Now().Round(time.Second),
|
||||
DoneCh: make(chan struct{}),
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
|
||||
h.l.Lock()
|
||||
@ -159,6 +162,7 @@ func (h *UiHook) PreApply(
|
||||
}
|
||||
|
||||
func (h *UiHook) stillApplying(state uiResourceState) {
|
||||
defer close(state.done)
|
||||
for {
|
||||
select {
|
||||
case <-state.DoneCh:
|
||||
|
@ -65,6 +65,11 @@ func TestUiHookPreApply_periodicTimer(t *testing.T) {
|
||||
|
||||
time.Sleep(3100 * time.Millisecond)
|
||||
|
||||
// stop the background writer
|
||||
uiState := h.resources[n.HumanId()]
|
||||
close(uiState.DoneCh)
|
||||
<-uiState.done
|
||||
|
||||
expectedOutput := `data.aws_availability_zones.available: Destroying... (ID: 2017-03-0...0000 UTC)
|
||||
data.aws_availability_zones.available: Still destroying... (ID: 2017-03-0...0000 UTC, 1s elapsed)
|
||||
data.aws_availability_zones.available: Still destroying... (ID: 2017-03-0...0000 UTC, 2s elapsed)
|
||||
|
Loading…
Reference in New Issue
Block a user