Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 078f160

Browse files
authored
Merge pull request #490 from Crazykev/test-log
Print integration test log when case failed
2 parents cfc48da + 457b075 commit 078f160

File tree

12 files changed

+66
-17
lines changed

12 files changed

+66
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,4 @@ _testmain.go
5858
# ignore test_data
5959
test_data
6060
!test_data/Makefile
61+
integration-test/config.json

Makefile.am

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ build-runv:
2222
go build -tags "static_build $(HYPER_BULD_TAGS)" -o runv .
2323
test-integration:
2424
cd integration-test/test_data && make
25-
cd integration-test && go test -check.v -test.timeout=120m ${TESTFLAGS} . ; ret=$$? ;\
26-
sync; sleep 20; sync; find /var/log/hyper/ -type f -exec echo -e '\n\nLog of ' {} ':' \; -exec cat {} \; ; exit $$ret
25+
cd integration-test && go test -check.v -test.timeout=120m ${TESTFLAGS} .

containerd/containerd.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ const (
3232
defaultStateDir = "/run/runv-containerd"
3333
defaultListenType = "unix"
3434
defaultGRPCEndpoint = "/run/runv-containerd/containerd.sock"
35+
// runv-containerd is a relativly short term program
36+
// since we can't change the flush interval in glog, flush here manaully.
37+
glogFlushInterval = 5 * time.Second
3538
)
3639

3740
var ContainerdCommand = cli.Command{
@@ -152,6 +155,8 @@ func daemon(sv *supervisor.Supervisor, address string) error {
152155
s := make(chan os.Signal, 2048)
153156
signal.Notify(s, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT)
154157

158+
go glogFlushDaemon()
159+
155160
server, err := startServer(address, sv)
156161
if err != nil {
157162
return err
@@ -161,6 +166,7 @@ func daemon(sv *supervisor.Supervisor, address string) error {
161166
glog.V(1).Infof("stopping containerd after receiving %s", sig)
162167
time.Sleep(3 * time.Second) // TODO: fix it by proper way
163168
server.Stop()
169+
glog.Flush()
164170
return nil
165171
}
166172

@@ -200,3 +206,9 @@ func startServer(address string, sv *supervisor.Supervisor) (*grpc.Server, error
200206
}()
201207
return s, nil
202208
}
209+
210+
func glogFlushDaemon() {
211+
for range time.NewTicker(glogFlushInterval).C {
212+
glog.Flush()
213+
}
214+
}

integration-test/exec_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
)
1616

1717
func (s *RunVSuite) TestExecHelloWorld(c *check.C) {
18+
defer s.PrintLog(c)
1819
ctrName := "testExecHelloWorld"
1920
spec := defaultTestSpec
2021
spec.Process.Args = []string{"sleep", "10"}
@@ -43,6 +44,7 @@ func (s *RunVSuite) TestExecHelloWorld(c *check.C) {
4344
}
4445

4546
func (s *RunVSuite) TestExecWithTty(c *check.C) {
47+
defer s.PrintLog(c)
4648
ctrName := "TestExecWithTty"
4749
spec := defaultTestSpec
4850
spec.Process.Args = []string{"sleep", "10"}
@@ -91,6 +93,7 @@ func (s *RunVSuite) TestExecWithTty(c *check.C) {
9193
}
9294

9395
func (s *RunVSuite) TestExecWithProcessJson(c *check.C) {
96+
defer s.PrintLog(c)
9497
process := specs.Process{
9598
Terminal: false,
9699
User: specs.User{},

integration-test/init_test.go

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,29 @@ package main
33
import (
44
"bytes"
55
"encoding/json"
6+
"fmt"
67
"io/ioutil"
78
"os"
89
"os/exec"
910
"path/filepath"
1011
"runtime"
1112
"testing"
13+
"time"
1214

1315
"github.com/docker/docker/integration-cli/checker"
1416
"github.com/go-check/check"
1517
"github.com/opencontainers/runtime-spec/specs-go"
1618
)
1719

1820
const (
19-
testDataDir = "test_data"
20-
busyboxTarName = "busybox.tar"
21-
configFileName = "config.json"
22-
kernelName = "kernel"
23-
initrdName = "hyper-initrd.img"
24-
binaryName = "runv"
25-
rootfsName = "rootfs"
21+
testDataDir = "test_data"
22+
busyboxTarName = "busybox.tar"
23+
configFileName = "config.json"
24+
kernelName = "kernel"
25+
initrdName = "hyper-initrd.img"
26+
binaryName = "runv"
27+
rootfsName = "rootfs"
28+
logFileNamePattern = "runv*INFO*"
2629
)
2730

2831
var (
@@ -63,6 +66,7 @@ type RunVSuite struct {
6366
initrdPath string
6467
bundlePath string
6568
configPath string
69+
logPath string
6670
}
6771

6872
var _ = check.Suite(&RunVSuite{})
@@ -110,12 +114,23 @@ func (s *RunVSuite) SetUpSuite(c *check.C) {
110114

111115
func (s *RunVSuite) TearDownSuite(c *check.C) {}
112116

113-
func (s *RunVSuite) SetUpTest(c *check.C) {}
117+
func (s *RunVSuite) SetUpTest(c *check.C) {
118+
s.logPath = c.MkDir()
119+
}
114120

115121
func (s *RunVSuite) TearDownTest(c *check.C) {
116122
// FIXME: Use runv kill/delete to do reliable garbage collection
117123
// after kill/delete functions are stable
118-
exec.Command("pkill", "-9", "runv-namespaced").Run()
119-
exec.Command("pkill", "-9", "qemu").Run()
120-
exec.Command("pkill", "-9", "containerd-nslistener")
124+
killAllRunvComponent(9)
125+
}
126+
127+
func (s *RunVSuite) PrintLog(c *check.C) {
128+
if c.Failed() {
129+
// kill runv gently to enable garbage collection and flush log
130+
killAllRunvComponent(15)
131+
time.Sleep(3 * time.Second)
132+
out, err := exec.Command("sh", "-c", fmt.Sprintf("find %s -type f -name '%s' -exec echo -e '\n\nLog of ' {} ':' \\; -exec cat {} \\;", s.logPath, logFileNamePattern)).CombinedOutput()
133+
c.Assert(err, checker.IsNil)
134+
c.Logf("Test case %s failed, retrieve runv log from directory %s:\n%s", c.TestName(), s.logPath, out)
135+
}
121136
}

integration-test/kill_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
)
1010

1111
func (s *RunVSuite) TestKillKILL(c *check.C) {
12+
defer s.PrintLog(c)
1213
ctrName := "testKillKILL"
1314
spec := defaultTestSpec
1415
c.Assert(s.addSpec(&spec), checker.IsNil)

integration-test/list_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type containerState struct {
2121
}
2222

2323
func (s *RunVSuite) TestListSleep(c *check.C) {
24+
defer s.PrintLog(c)
2425
ctrName := "testListSleep"
2526
spec := defaultTestSpec
2627
spec.Process.Args = []string{"sleep", "10"}
@@ -48,6 +49,7 @@ func (s *RunVSuite) TestListSleep(c *check.C) {
4849
}
4950

5051
func (s *RunVSuite) TestListSleepJson(c *check.C) {
52+
defer s.PrintLog(c)
5153
ctrName := "testListSleepJson"
5254
spec := defaultTestSpec
5355
spec.Process.Args = []string{"sleep", "10"}

integration-test/spec_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
)
1414

1515
func (s *RunVSuite) TestSpecDefault(c *check.C) {
16+
defer s.PrintLog(c)
1617
expectedSpec := defaultTestSpec
1718
expectedSpec.Process.Terminal = true
1819
expectedSpec.Process.Args = []string{"sh"}

integration-test/start_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
)
1717

1818
func (s *RunVSuite) TestStartHelloworld(c *check.C) {
19+
defer s.PrintLog(c)
1920
spec := defaultTestSpec
2021
spec.Process.Args = []string{"echo", "hello"}
2122
c.Assert(s.addSpec(&spec), checker.IsNil)
@@ -26,6 +27,7 @@ func (s *RunVSuite) TestStartHelloworld(c *check.C) {
2627
}
2728

2829
func (s *RunVSuite) TestStartPid(c *check.C) {
30+
defer s.PrintLog(c)
2931
c.Skip("enable this after fixing")
3032
ctrName := "testStartPid"
3133
spec := defaultTestSpec
@@ -80,6 +82,7 @@ func (s *RunVSuite) TestStartPid(c *check.C) {
8082
}
8183

8284
func (s *RunVSuite) TestStartWithTty(c *check.C) {
85+
defer s.PrintLog(c)
8386
ctrName := "TestStartWithTty"
8487
spec := defaultTestSpec
8588
spec.Process.Terminal = true

integration-test/state_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func (s *RunVSuite) TestStateSleep(c *check.C) {
3131
//TODO: enable this after fixing!!!
3232
//c.Skip("enable this after fixing")
3333

34+
defer s.PrintLog(c)
3435
ctrName := "testStateSleep"
3536
spec := defaultTestSpec
3637
spec.Process.Args = []string{"sleep", "10"}

0 commit comments

Comments
 (0)