From d87b68efe8216faf18fb161f2c74938285a7b52b Mon Sep 17 00:00:00 2001 From: Mark Peek Date: Sat, 10 Oct 2015 14:32:39 -0700 Subject: [PATCH] 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. --- provisioner/windows-restart/provisioner_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/provisioner/windows-restart/provisioner_test.go b/provisioner/windows-restart/provisioner_test.go index 247452c22..1f3f70ba3 100644 --- a/provisioner/windows-restart/provisioner_test.go +++ b/provisioner/windows-restart/provisioner_test.go @@ -268,15 +268,18 @@ func TestProvision_waitForCommunicatorWithCancel(t *testing.T) { // Run 2 goroutines; // 1st to call waitForCommunicator (that will always fail) // 2nd to cancel the operation + waitStart := make(chan bool) waitDone := make(chan bool) go func() { + waitStart <- true err = waitForCommunicator(p) + waitDone <- true }() go func() { time.Sleep(10 * time.Millisecond) + <-waitStart p.Cancel() - waitDone <- true }() <-waitDone @@ -327,13 +330,15 @@ func TestProvision_Cancel(t *testing.T) { comm := new(packer.MockCommunicator) p.Prepare(config) + waitStart := make(chan bool) waitDone := make(chan bool) // Block until cancel comes through waitForCommunicator = func(p *Provisioner) error { + waitStart <- true for { select { - case <-waitDone: + case <-p.cancel: } } } @@ -346,6 +351,7 @@ func TestProvision_Cancel(t *testing.T) { }() go func() { + <-waitStart p.Cancel() }() <-waitDone