fix race in hook ui PreApply test

Fix a race in the PreApply test, and make the PreApply background task
actually concealable.
This commit is contained in:
James Bardin 2017-03-17 11:04:27 -04:00
parent c9df11e32f
commit b9931c437d
2 changed files with 9 additions and 0 deletions

View File

@ -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:

View File

@ -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)