Syncronize cancellation in windows-restart tests

Two windows-restart tests would timeout and fail due to the cancellation
thread firing before the cancel object was created. This change syncronizes
the start of the threads to prevent this from occurring.
This commit is contained in:
Mark Peek 2015-10-10 14:32:39 -07:00
parent 23d5e50600
commit d87b68efe8
1 changed files with 8 additions and 2 deletions

View File

@ -268,15 +268,18 @@ func TestProvision_waitForCommunicatorWithCancel(t *testing.T) {
// Run 2 goroutines; // Run 2 goroutines;
// 1st to call waitForCommunicator (that will always fail) // 1st to call waitForCommunicator (that will always fail)
// 2nd to cancel the operation // 2nd to cancel the operation
waitStart := make(chan bool)
waitDone := make(chan bool) waitDone := make(chan bool)
go func() { go func() {
waitStart <- true
err = waitForCommunicator(p) err = waitForCommunicator(p)
waitDone <- true
}() }()
go func() { go func() {
time.Sleep(10 * time.Millisecond) time.Sleep(10 * time.Millisecond)
<-waitStart
p.Cancel() p.Cancel()
waitDone <- true
}() }()
<-waitDone <-waitDone
@ -327,13 +330,15 @@ func TestProvision_Cancel(t *testing.T) {
comm := new(packer.MockCommunicator) comm := new(packer.MockCommunicator)
p.Prepare(config) p.Prepare(config)
waitStart := make(chan bool)
waitDone := make(chan bool) waitDone := make(chan bool)
// Block until cancel comes through // Block until cancel comes through
waitForCommunicator = func(p *Provisioner) error { waitForCommunicator = func(p *Provisioner) error {
waitStart <- true
for { for {
select { select {
case <-waitDone: case <-p.cancel:
} }
} }
} }
@ -346,6 +351,7 @@ func TestProvision_Cancel(t *testing.T) {
}() }()
go func() { go func() {
<-waitStart
p.Cancel() p.Cancel()
}() }()
<-waitDone <-waitDone