mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-26 15:32:30 +00:00
Merge pull request #209 from sboeuf/fix_unit_tests
virtcontainers: Fix unit tests
This commit is contained in:
commit
8088a62805
@ -242,8 +242,9 @@ func TestCCShimStartDetachSuccessful(t *testing.T) {
|
||||
|
||||
testCCShimStart(t, sandbox, params, false)
|
||||
|
||||
readCh := make(chan error)
|
||||
readCh := make(chan error, 1)
|
||||
go func() {
|
||||
defer close(readCh)
|
||||
bufStdout := make([]byte, 1024)
|
||||
n, err := rStdout.Read(bufStdout)
|
||||
if err != nil && err != io.EOF {
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
@ -82,9 +83,11 @@ func (h *Hook) runHook() error {
|
||||
return fmt.Errorf("%s: stdout: %s, stderr: %s", err, stdout.String(), stderr.String())
|
||||
}
|
||||
} else {
|
||||
done := make(chan error)
|
||||
|
||||
go func() { done <- cmd.Wait() }()
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
done <- cmd.Wait()
|
||||
close(done)
|
||||
}()
|
||||
|
||||
select {
|
||||
case err := <-done:
|
||||
@ -92,6 +95,10 @@ func (h *Hook) runHook() error {
|
||||
return fmt.Errorf("%s: stdout: %s, stderr: %s", err, stdout.String(), stderr.String())
|
||||
}
|
||||
case <-time.After(time.Duration(h.Timeout) * time.Second):
|
||||
if err := syscall.Kill(cmd.Process.Pid, syscall.SIGKILL); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return fmt.Errorf("Hook timeout")
|
||||
}
|
||||
}
|
||||
|
@ -236,8 +236,9 @@ func TestKataShimStartDetachSuccessful(t *testing.T) {
|
||||
|
||||
testKataShimStart(t, sandbox, params, false)
|
||||
|
||||
readCh := make(chan error)
|
||||
readCh := make(chan error, 1)
|
||||
go func() {
|
||||
defer close(readCh)
|
||||
bufStdout := make([]byte, 1024)
|
||||
n, err := rStdout.Read(bufStdout)
|
||||
if err != nil && err != io.EOF {
|
||||
|
@ -21,5 +21,5 @@ type noopShim struct{}
|
||||
// start is the noopShim start implementation for testing purpose.
|
||||
// It does nothing.
|
||||
func (s *noopShim) start(sandbox Sandbox, params ShimParams) (int, error) {
|
||||
return 1000, nil
|
||||
return 0, nil
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ func TestNoopShimStart(t *testing.T) {
|
||||
s := &noopShim{}
|
||||
sandbox := Sandbox{}
|
||||
params := ShimParams{}
|
||||
expected := 1000
|
||||
expected := 0
|
||||
|
||||
pid, err := s.start(sandbox, params)
|
||||
if err != nil {
|
||||
|
@ -31,6 +31,8 @@ const testToken = "pF56IaDpuax6hihJ5PneB8JypqmOvjkqY-wKGVYqgIM="
|
||||
|
||||
// CCProxyMock is an object mocking clearcontainers Proxy
|
||||
type CCProxyMock struct {
|
||||
sync.Mutex
|
||||
|
||||
t *testing.T
|
||||
wg sync.WaitGroup
|
||||
connectionPath string
|
||||
@ -50,6 +52,8 @@ type CCProxyMock struct {
|
||||
Signal chan ShimSignal
|
||||
ShimDisconnected chan bool
|
||||
StdinReceived chan bool
|
||||
|
||||
stopped bool
|
||||
}
|
||||
|
||||
// NewCCProxyMock creates a hyperstart instance
|
||||
@ -296,10 +300,19 @@ func (proxy *CCProxyMock) serve() {
|
||||
|
||||
// Start invokes mock proxy instance to start listening.
|
||||
func (proxy *CCProxyMock) Start() {
|
||||
proxy.stopped = false
|
||||
proxy.startListening()
|
||||
go func() {
|
||||
for {
|
||||
proxy.serve()
|
||||
|
||||
proxy.Lock()
|
||||
stopped := proxy.stopped
|
||||
proxy.Unlock()
|
||||
|
||||
if stopped {
|
||||
break
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
@ -307,6 +320,10 @@ func (proxy *CCProxyMock) Start() {
|
||||
// Stop causes mock proxy instance to stop listening,
|
||||
// close connection to client and close all channels
|
||||
func (proxy *CCProxyMock) Stop() {
|
||||
proxy.Lock()
|
||||
proxy.stopped = true
|
||||
proxy.Unlock()
|
||||
|
||||
proxy.listener.Close()
|
||||
|
||||
if proxy.cl != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user