@@ -2,19 +2,13 @@ package container // import "github.com/docker/docker/integration/container"
22
33import (
44 "context"
5- "fmt"
6- "strconv"
7- "strings"
85 "testing"
96 "time"
107
11- "github.com/docker/docker/api/types"
128 "github.com/docker/docker/integration/internal/container"
139 "github.com/docker/docker/internal/test/request"
1410 "gotest.tools/assert"
15- "gotest.tools/icmd"
1611 "gotest.tools/poll"
17- "gotest.tools/skip"
1812)
1913
2014func TestStopContainerWithRestartPolicyAlways (t * testing.T ) {
@@ -42,86 +36,3 @@ func TestStopContainerWithRestartPolicyAlways(t *testing.T) {
4236 poll .WaitOn (t , container .IsStopped (ctx , client , name ), poll .WithDelay (100 * time .Millisecond ))
4337 }
4438}
45-
46- // TestStopContainerWithTimeout checks that ContainerStop with
47- // a timeout works as documented, i.e. in case of negative timeout
48- // waiting is not limited (issue #35311).
49- func TestStopContainerWithTimeout (t * testing.T ) {
50- defer setupTest (t )()
51- client := request .NewAPIClient (t )
52- ctx := context .Background ()
53-
54- testCmd := container .WithCmd ("sh" , "-c" , "sleep 2 && exit 42" )
55- testData := []struct {
56- doc string
57- timeout int
58- expectedExitCode int
59- }{
60- // In case container is forcefully killed, 137 is returned,
61- // otherwise the exit code from the above script
62- {
63- "zero timeout: expect forceful container kill" ,
64- 0 , 137 ,
65- },
66- {
67- "too small timeout: expect forceful container kill" ,
68- 1 , 137 ,
69- },
70- {
71- "big enough timeout: expect graceful container stop" ,
72- 3 , 42 ,
73- },
74- {
75- "unlimited timeout: expect graceful container stop" ,
76- - 1 , 42 ,
77- },
78- }
79-
80- for _ , d := range testData {
81- d := d
82- t .Run (strconv .Itoa (d .timeout ), func (t * testing.T ) {
83- t .Parallel ()
84- id := container .Run (t , ctx , client , testCmd )
85-
86- timeout := time .Duration (d .timeout ) * time .Second
87- err := client .ContainerStop (ctx , id , & timeout )
88- assert .NilError (t , err )
89-
90- poll .WaitOn (t , container .IsStopped (ctx , client , id ),
91- poll .WithDelay (100 * time .Millisecond ))
92-
93- inspect , err := client .ContainerInspect (ctx , id )
94- assert .NilError (t , err )
95- assert .Equal (t , inspect .State .ExitCode , d .expectedExitCode )
96- })
97- }
98- }
99-
100- func TestDeleteDevicemapper (t * testing.T ) {
101- skip .If (t , testEnv .DaemonInfo .Driver != "devicemapper" )
102- skip .If (t , testEnv .IsRemoteDaemon , "cannot start daemon on remote test run" )
103-
104- defer setupTest (t )()
105- client := request .NewAPIClient (t )
106- ctx := context .Background ()
107-
108- id := container .Run (t , ctx , client , container .WithName ("foo-" + t .Name ()), container .WithCmd ("echo" ))
109-
110- poll .WaitOn (t , container .IsStopped (ctx , client , id ), poll .WithDelay (100 * time .Millisecond ))
111-
112- inspect , err := client .ContainerInspect (ctx , id )
113- assert .NilError (t , err )
114-
115- deviceID := inspect .GraphDriver .Data ["DeviceId" ]
116-
117- // Find pool name from device name
118- deviceName := inspect .GraphDriver .Data ["DeviceName" ]
119- devicePrefix := deviceName [:strings .LastIndex (deviceName , "-" )]
120- devicePool := fmt .Sprintf ("/dev/mapper/%s-pool" , devicePrefix )
121-
122- result := icmd .RunCommand ("dmsetup" , "message" , devicePool , "0" , fmt .Sprintf ("delete %s" , deviceID ))
123- result .Assert (t , icmd .Success )
124-
125- err = client .ContainerRemove (ctx , id , types.ContainerRemoveOptions {})
126- assert .NilError (t , err )
127- }
0 commit comments