test: fix flaky TestRunAttachTermination
This patch fixes the `TestRunAttachTermination` flaky runs. It seems like we weren't halting on the `waitFunc` so if the process was fast enough to setup the signal handler and execute `waitExitOrRemoved`. We now instead wait for the `killCh` channel to close inside the mocked `waitFunc`. Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
This commit is contained in:
parent
2d74733942
commit
966b44183f
@ -147,7 +147,6 @@ func TestRunAttachTermination(t *testing.T) {
|
|||||||
_ = p.Close()
|
_ = p.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var conn net.Conn
|
|
||||||
killCh := make(chan struct{})
|
killCh := make(chan struct{})
|
||||||
attachCh := make(chan struct{})
|
attachCh := make(chan struct{})
|
||||||
fakeCLI := test.NewFakeCli(&fakeClient{
|
fakeCLI := test.NewFakeCli(&fakeClient{
|
||||||
@ -156,13 +155,14 @@ func TestRunAttachTermination(t *testing.T) {
|
|||||||
ID: "id",
|
ID: "id",
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
containerKillFunc: func(ctx context.Context, containerID, signal string) error {
|
containerKillFunc: func(ctx context.Context, containerID, sig string) error {
|
||||||
killCh <- struct{}{}
|
if sig == "TERM" {
|
||||||
|
close(killCh)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
containerAttachFunc: func(ctx context.Context, containerID string, options container.AttachOptions) (types.HijackedResponse, error) {
|
containerAttachFunc: func(ctx context.Context, containerID string, options container.AttachOptions) (types.HijackedResponse, error) {
|
||||||
server, client := net.Pipe()
|
server, client := net.Pipe()
|
||||||
conn = server
|
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
_ = server.Close()
|
_ = server.Close()
|
||||||
})
|
})
|
||||||
@ -172,7 +172,7 @@ func TestRunAttachTermination(t *testing.T) {
|
|||||||
waitFunc: func(_ string) (<-chan container.WaitResponse, <-chan error) {
|
waitFunc: func(_ string) (<-chan container.WaitResponse, <-chan error) {
|
||||||
responseChan := make(chan container.WaitResponse, 1)
|
responseChan := make(chan container.WaitResponse, 1)
|
||||||
errChan := make(chan error)
|
errChan := make(chan error)
|
||||||
|
<-killCh
|
||||||
responseChan <- container.WaitResponse{
|
responseChan <- container.WaitResponse{
|
||||||
StatusCode: 130,
|
StatusCode: 130,
|
||||||
}
|
}
|
||||||
@ -201,9 +201,7 @@ func TestRunAttachTermination(t *testing.T) {
|
|||||||
case <-attachCh:
|
case <-attachCh:
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NilError(t, syscall.Kill(syscall.Getpid(), syscall.SIGINT))
|
assert.NilError(t, syscall.Kill(syscall.Getpid(), syscall.SIGTERM))
|
||||||
// end stream from "container" so that we'll detach
|
|
||||||
conn.Close()
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-killCh:
|
case <-killCh:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user