forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic virt-launcher sanity check unit tests
Signed-off-by: David Vossel <[email protected]>
- Loading branch information
1 parent
9815d81
commit 3ba044e
Showing
5 changed files
with
180 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* This file is part of the KubeVirt project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* Copyright 2017 Red Hat, Inc. | ||
* | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
func main() { | ||
fmt.Printf("Started fake qemu process\n") | ||
time.Sleep(60 * time.Second) | ||
fmt.Printf("Exit fake qemu process\n") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* This file is part of the KubeVirt project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* Copyright 2017 Red Hat, Inc. | ||
* | ||
*/ | ||
|
||
package virtlauncher | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"testing" | ||
) | ||
|
||
func TestVirtLauncher(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "VirtLauncher Test Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* This file is part of the KubeVirt project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* Copyright 2017 Red Hat, Inc. | ||
* | ||
*/ | ||
|
||
package virtlauncher | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"strings" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("VirtLauncher", func() { | ||
var mon *monitor | ||
var cmd *exec.Cmd | ||
|
||
dir := os.Getenv("PWD") | ||
dir = strings.TrimSuffix(dir, "pkg/virt-launcher") | ||
|
||
processName := "fake-qemu-process" | ||
processPath := dir + "/cmd/fake-qemu-process/" + processName | ||
|
||
StartProcess := func() { | ||
cmd = exec.Command(processPath) | ||
err := cmd.Start() | ||
Expect(err).ToNot(HaveOccurred()) | ||
} | ||
|
||
StopProcess := func() { | ||
cmd.Process.Kill() | ||
cmd.Wait() | ||
} | ||
|
||
VerifyProcessStarted := func() { | ||
Eventually(func() bool { | ||
|
||
mon.refresh() | ||
if mon.pid != 0 { | ||
return true | ||
} | ||
return false | ||
|
||
}).Should(BeTrue()) | ||
|
||
} | ||
|
||
VerifyProcessStopped := func() { | ||
Eventually(func() bool { | ||
|
||
mon.refresh() | ||
if mon.pid == 0 && mon.isDone == true { | ||
return true | ||
} | ||
return false | ||
|
||
}).Should(BeTrue()) | ||
|
||
} | ||
|
||
BeforeEach(func() { | ||
mon = &monitor{ | ||
exename: processName, | ||
debugMode: true, | ||
} | ||
}) | ||
|
||
Describe("VirtLauncher", func() { | ||
Context("process monitor", func() { | ||
It("verify pid detection works", func() { | ||
StartProcess() | ||
VerifyProcessStarted() | ||
StopProcess() | ||
VerifyProcessStopped() | ||
}) | ||
|
||
It("verify start timeout works", func() { | ||
done := make(chan string) | ||
|
||
go func() { | ||
mon.RunForever(time.Second) | ||
done <- "exit" | ||
}() | ||
noExitCheck := time.After(3 * time.Second) | ||
|
||
exited := false | ||
select { | ||
case <-noExitCheck: | ||
case <-done: | ||
exited = true | ||
} | ||
|
||
Expect(exited).To(Equal(true)) | ||
}) | ||
}) | ||
}) | ||
}) |