Skip to content

Commit

Permalink
Merge pull request kubevirt#1283 from davidvossel/enable-race-detect
Browse files Browse the repository at this point in the history
Turn on -race for test suite
  • Loading branch information
rmohr authored Jul 6, 2018
2 parents e2758ff + 35cdf40 commit 73edb2f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion hack/build-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if [ $# -eq 0 ]; then
if [ "${target}" = "test" ]; then
(
cd ${KUBEVIRT_DIR}/pkg
go ${target} -v ./...
go ${target} -v -race ./...
)
else
(
Expand Down
16 changes: 9 additions & 7 deletions pkg/virt-handler/device-manager/device_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,24 @@ var _ = Describe("Device Controller", func() {
By(fmt.Sprintf("Device Path: %s", devicePath))

timeout := make(chan struct{})

go func() {
errChan := make(chan error)
go func(devicePath string) {
time.Sleep(1 * time.Second)

fileObj, err := os.Create(devicePath)
Expect(err).ToNot(HaveOccurred())
fileObj.Close()
}()
errChan <- err
}(devicePath)

go func() {
go func(timeout chan struct{}) {
time.Sleep(5 * time.Second)
close(timeout)
}()
}(timeout)

err := deviceController.waitForPath(devicePath, timeout)
err := <-errChan
Expect(err).ToNot(HaveOccurred())

err = deviceController.waitForPath(devicePath, timeout)
Expect(err).ToNot(HaveOccurred())
})
})
Expand Down
13 changes: 13 additions & 0 deletions pkg/virt-launcher/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"os"
"os/exec"
"strings"
"sync"
"syscall"
"time"

Expand All @@ -36,6 +37,7 @@ import (
var _ = Describe("VirtLauncher", func() {
var mon *monitor
var cmd *exec.Cmd
var cmdLock sync.Mutex

uuid := "123-123-123-123"

Expand All @@ -52,6 +54,9 @@ var _ = Describe("VirtLauncher", func() {
processStarted := false

StartProcess := func() {
cmdLock.Lock()
defer cmdLock.Unlock()

cmd = exec.Command(processPath, "--uuid", uuid)
err := cmd.Start()
Expect(err).ToNot(HaveOccurred())
Expand All @@ -63,11 +68,17 @@ var _ = Describe("VirtLauncher", func() {
}

StopProcess := func() {
cmdLock.Lock()
defer cmdLock.Unlock()

cmd.Process.Kill()
processStarted = false
}

CleanupProcess := func() {
cmdLock.Lock()
defer cmdLock.Unlock()

cmd.Wait()
}

Expand Down Expand Up @@ -114,6 +125,8 @@ var _ = Describe("VirtLauncher", func() {
AfterEach(func() {
os.RemoveAll(tmpDir)
if processStarted == true {
cmdLock.Lock()
defer cmdLock.Unlock()
cmd.Process.Kill()
}
processStarted = false
Expand Down

0 comments on commit 73edb2f

Please sign in to comment.