Browse code

integration-cli: fix TestAttachDetach, rm TestAttachDetachTruncatedID

It looks like the logic of the test became wrong after commit
ae0883c ("Move TestAttachDetach to integration-cli").

The original logic was:
* (a few first steps skipped for clarity)
* send escape sequence to "attach";
* check "attach" is exiting (i.e. escape sequence works);
* check the container is still alive;
* kill the container.

Also, timeouts were big at that time, in the order of seconds.

The logic after the above mentioned commit and until now is:
* ...
* send escape sequence to "attach";
* check the container is running (why shouldn't it?);
* kill the container;
* checks that the "attach" has exited.

So, from the "let's check detach using escape sequence is working"
the test became something like "let's check that attach is gone
once we kill the container".

Let's fix the above test, also increasing the timeout waiting
for attach to exit (which fails from time to time on power CI).

Now, the second test, TestAttachDetachTruncatedID, does the exact
same thing, except it uses a truncated container ID. It does not
seem to be of much value, so let's remove it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>

Kir Kolyshkin authored on 2018/08/25 06:37:26
Showing 1 changed files
... ...
@@ -10,7 +10,6 @@ import (
10 10
 	"time"
11 11
 
12 12
 	"github.com/docker/docker/integration-cli/checker"
13
-	"github.com/docker/docker/pkg/stringid"
14 13
 	"github.com/go-check/check"
15 14
 	"github.com/kr/pty"
16 15
 )
... ...
@@ -146,7 +145,7 @@ func (s *DockerSuite) TestAttachDetach(c *check.C) {
146 146
 	c.Assert(err, check.IsNil)
147 147
 	out, err = bufio.NewReader(stdout).ReadString('\n')
148 148
 	c.Assert(err, check.IsNil)
149
-	c.Assert(strings.TrimSpace(out), checker.Equals, "hello", check.Commentf("expected 'hello', got %q", out))
149
+	c.Assert(strings.TrimSpace(out), checker.Equals, "hello")
150 150
 
151 151
 	// escape sequence
152 152
 	_, err = cpty.Write([]byte{16})
... ...
@@ -158,72 +157,15 @@ func (s *DockerSuite) TestAttachDetach(c *check.C) {
158 158
 	ch := make(chan struct{})
159 159
 	go func() {
160 160
 		cmd.Wait()
161
-		ch <- struct{}{}
162
-	}()
163
-
164
-	running := inspectField(c, id, "State.Running")
165
-	c.Assert(running, checker.Equals, "true", check.Commentf("expected container to still be running"))
166
-
167
-	go func() {
168
-		dockerCmdWithResult("kill", id)
161
+		close(ch)
169 162
 	}()
170 163
 
171 164
 	select {
172 165
 	case <-ch:
173
-	case <-time.After(10 * time.Millisecond):
166
+	case <-time.After(1 * time.Second):
174 167
 		c.Fatal("timed out waiting for container to exit")
175 168
 	}
176 169
 
177
-}
178
-
179
-// TestAttachDetachTruncatedID checks that attach in tty mode can be detached
180
-func (s *DockerSuite) TestAttachDetachTruncatedID(c *check.C) {
181
-	out, _ := dockerCmd(c, "run", "-itd", "busybox", "cat")
182
-	id := stringid.TruncateID(strings.TrimSpace(out))
183
-	c.Assert(waitRun(id), check.IsNil)
184
-
185
-	cpty, tty, err := pty.Open()
186
-	c.Assert(err, checker.IsNil)
187
-	defer cpty.Close()
188
-
189
-	cmd := exec.Command(dockerBinary, "attach", id)
190
-	cmd.Stdin = tty
191
-	stdout, err := cmd.StdoutPipe()
192
-	c.Assert(err, checker.IsNil)
193
-	defer stdout.Close()
194
-	err = cmd.Start()
195
-	c.Assert(err, checker.IsNil)
196
-
197
-	_, err = cpty.Write([]byte("hello\n"))
198
-	c.Assert(err, checker.IsNil)
199
-	out, err = bufio.NewReader(stdout).ReadString('\n')
200
-	c.Assert(err, checker.IsNil)
201
-	c.Assert(strings.TrimSpace(out), checker.Equals, "hello", check.Commentf("expected 'hello', got %q", out))
202
-
203
-	// escape sequence
204
-	_, err = cpty.Write([]byte{16})
205
-	c.Assert(err, checker.IsNil)
206
-	time.Sleep(100 * time.Millisecond)
207
-	_, err = cpty.Write([]byte{17})
208
-	c.Assert(err, checker.IsNil)
209
-
210
-	ch := make(chan struct{})
211
-	go func() {
212
-		cmd.Wait()
213
-		ch <- struct{}{}
214
-	}()
215
-
216 170
 	running := inspectField(c, id, "State.Running")
217
-	c.Assert(running, checker.Equals, "true", check.Commentf("expected container to still be running"))
218
-
219
-	go func() {
220
-		dockerCmdWithResult("kill", id)
221
-	}()
222
-
223
-	select {
224
-	case <-ch:
225
-	case <-time.After(10 * time.Millisecond):
226
-		c.Fatal("timed out waiting for container to exit")
227
-	}
228
-
171
+	c.Assert(running, checker.Equals, "true") // container should be running
229 172
 }