@@ -3,9 +3,7 @@ package main
33import (
44 "time"
55
6- "github.com/alibaba/pouch/apis/types"
76 "github.com/alibaba/pouch/test/environment"
8- "github.com/alibaba/pouch/test/request"
97
108 "github.com/go-check/check"
119)
@@ -26,70 +24,38 @@ func (suite *APIContainerExecInspectSuite) SetUpTest(c *check.C) {
2624
2725// TestContainerCreateExecOk tests execing containers is OK.
2826func (suite * APIContainerExecInspectSuite ) TestContainerExecInspectOk (c * check.C ) {
29- c .Skip ("skip flaky test due to issue#1372" )
3027 cname := "TestContainerExecInspectOk"
3128
3229 CreateBusyboxContainerOk (c , cname )
30+ defer DelContainerForceMultyTime (c , cname )
3331
3432 StartContainerOk (c , cname )
3533
36- obj := map [string ]interface {}{
37- "Cmd" : []string {"sleep" , "9" },
38- "Detach" : true ,
39- }
40- body := request .WithJSONBody (obj )
41- resp , err := request .Post ("/containers/" + cname + "/exec" , body )
42- c .Assert (err , check .IsNil )
43- CheckRespStatus (c , resp , 201 )
44-
45- var execCreateResp types.ExecCreateResp
46- err = request .DecodeBody (& execCreateResp , resp .Body )
47- c .Assert (err , check .IsNil )
48-
49- execid := execCreateResp .ID
50-
51- // inspect the exec before exec start
52- resp , err = request .Get ("/exec/" + execid + "/json" )
53- c .Assert (err , check .IsNil )
54- CheckRespStatus (c , resp , 200 )
55-
56- var execInspect01 types.ContainerExecInspect
57- request .DecodeBody (& execInspect01 , resp .Body )
34+ // create an exec and get the execID
35+ // and inspect the exec before exec start
5836
59- c .Assert (execInspect01 .Running , check .Equals , false )
60- c .Assert (execInspect01 .ExitCode , check .Equals , int64 (0 ))
61-
62- // start the exec
37+ execid := CreateExecCmdOk (c , cname , "sleep" , "9" )
6338 {
64- resp , conn , _ , err := StartContainerExec (c , execid , false , false )
65- c .Assert (err , check .IsNil )
66- CheckRespStatus (c , resp , 101 )
67- c .Assert (conn .Close (), check .IsNil )
39+ execInspectResp := InspectExecOk (execid )
40+ c .Assert (execInspectResp .Running , check .Equals , false )
41+ c .Assert (execInspectResp .ExitCode , check .Equals , int64 (0 ))
6842 }
6943
70- // inspect the exec after exec start
71- resp , err = request .Get ("/exec/" + execid + "/json" )
72- c .Assert (err , check .IsNil )
73- CheckRespStatus (c , resp , 200 )
74-
75- var execInspect02 types.ContainerExecInspect
76- request .DecodeBody (& execInspect02 , resp .Body )
44+ // start the exec
45+ StartContainerExecOk (c , execid )
7746
78- c .Assert (execInspect02 .Running , check .Equals , true )
79- c .Assert (execInspect02 .ExitCode , check .Equals , int64 (0 ))
47+ // inspect the exec after exec start
48+ {
49+ execInspectResp = InspectExecOk (execid )
50+ c .Assert (execInspectResp .Running , check .Equals , true )
51+ c .Assert (execInspectResp .ExitCode , check .Equals , int64 (0 ))
52+ }
8053
8154 // sleep 10s to wait the process exit
82- time .Sleep (10 * time .Second )
83-
84- resp , err = request .Get ("/exec/" + execid + "/json" )
85- c .Assert (err , check .IsNil )
86- CheckRespStatus (c , resp , 200 )
87-
88- var execInspect03 types.ContainerExecInspect
89- request .DecodeBody (& execInspect03 , resp .Body )
90-
91- c .Assert (execInspect03 .Running , check .Equals , false )
92- c .Assert (execInspect03 .ExitCode , check .Equals , int64 (0 ))
93-
94- DelContainerForceMultyTime (c , cname )
55+ {
56+ time .Sleep (10 * time .Second )
57+ execInspectResp = InspectExecOk (execid )
58+ c .Assert (execInspectResp .Running , check .Equals , false )
59+ c .Assert (execInspectResp .ExitCode , check .Equals , int64 (0 ))
60+ }
9561}
0 commit comments