stop using goroutines in TestPausedProvisionerProvision_waits

to render the test less flaky.

this should fix #7684
This commit is contained in:
Adrien Delorme 2019-05-24 17:56:27 +02:00
parent 4b0f888a1c
commit dc631530d2
1 changed files with 20 additions and 20 deletions

View File

@ -2,6 +2,7 @@ package packer
import (
"context"
"fmt"
"testing"
"time"
)
@ -126,30 +127,29 @@ func TestPausedProvisionerProvision(t *testing.T) {
}
func TestPausedProvisionerProvision_waits(t *testing.T) {
mock := new(MockProvisioner)
startTime := time.Now()
waitTime := 50 * time.Millisecond
prov := &PausedProvisioner{
PauseBefore: 50 * time.Millisecond,
Provisioner: mock,
PauseBefore: waitTime,
Provisioner: &MockProvisioner{
ProvFunc: func(context.Context) error {
timeSinceStartTime := time.Since(startTime)
if timeSinceStartTime < waitTime {
return fmt.Errorf("Spent not enough time waiting: %s", timeSinceStartTime)
}
if timeSinceStartTime > waitTime+10*time.Millisecond {
return fmt.Errorf("Spent too much time waiting: %s", timeSinceStartTime)
}
dataCh := make(chan struct{})
mock.ProvFunc = func(context.Context) error {
close(dataCh)
return nil
},
},
}
go prov.Provision(context.Background(), testUi(), new(MockCommunicator))
err := prov.Provision(context.Background(), testUi(), new(MockCommunicator))
select {
case <-time.After(10 * time.Millisecond):
case <-dataCh:
t.Fatal("should not be called")
}
select {
case <-time.After(100 * time.Millisecond):
t.Fatal("never called")
case <-dataCh:
if err != nil {
t.Fatalf("prov failed: %v", err)
}
}