Skip to content

Commit 4aecba8

Browse files
committed
test: fix flaky TestRunAttachTermination
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
1 parent 2d74733 commit 4aecba8

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

cli/command/container/run_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ func TestRunAttachTermination(t *testing.T) {
147147
_ = p.Close()
148148
}()
149149

150-
var conn net.Conn
151150
killCh := make(chan struct{})
152151
attachCh := make(chan struct{})
153152
fakeCLI := test.NewFakeCli(&fakeClient{
@@ -156,23 +155,28 @@ func TestRunAttachTermination(t *testing.T) {
156155
ID: "id",
157156
}, nil
158157
},
159-
containerKillFunc: func(ctx context.Context, containerID, signal string) error {
160-
killCh <- struct{}{}
158+
containerKillFunc: func(ctx context.Context, containerID, sig string) error {
159+
t.Logf("KillFunc called")
160+
if sig == "TERM" {
161+
close(killCh)
162+
}
161163
return nil
162164
},
163165
containerAttachFunc: func(ctx context.Context, containerID string, options container.AttachOptions) (types.HijackedResponse, error) {
166+
t.Logf("AttachFunc called")
164167
server, client := net.Pipe()
165-
conn = server
166168
t.Cleanup(func() {
167169
_ = server.Close()
168170
})
169171
attachCh <- struct{}{}
170172
return types.NewHijackedResponse(client, types.MediaTypeRawStream), nil
171173
},
172174
waitFunc: func(_ string) (<-chan container.WaitResponse, <-chan error) {
175+
t.Logf("WaitFunc called")
173176
responseChan := make(chan container.WaitResponse, 1)
174177
errChan := make(chan error)
175-
178+
<-killCh
179+
t.Logf("WaitFunc got closed")
176180
responseChan <- container.WaitResponse{
177181
StatusCode: 130,
178182
}
@@ -201,9 +205,7 @@ func TestRunAttachTermination(t *testing.T) {
201205
case <-attachCh:
202206
}
203207

204-
assert.NilError(t, syscall.Kill(syscall.Getpid(), syscall.SIGINT))
205-
// end stream from "container" so that we'll detach
206-
conn.Close()
208+
assert.NilError(t, syscall.Kill(syscall.Getpid(), syscall.SIGTERM))
207209

208210
select {
209211
case <-killCh:

0 commit comments

Comments
 (0)