integration/TestLiveRestore: Wait for process to exit

Replace `time.Sleep` with a poll that checks if process no longer exists
to avoid possible race condition.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
(cherry picked from commit 3a0af5ad30)
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski 2023-11-29 15:37:04 +01:00
parent f0b5ca47fb
commit d0b5a5a8a5
No known key found for this signature in database
GPG key ID: B85EFCFE26DEF92A
2 changed files with 27 additions and 3 deletions

View file

@ -14,7 +14,6 @@ import (
"strings" "strings"
"syscall" "syscall"
"testing" "testing"
"time"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/mount" "github.com/docker/docker/api/types/mount"
@ -22,6 +21,7 @@ import (
"github.com/docker/docker/daemon/config" "github.com/docker/docker/daemon/config"
"github.com/docker/docker/errdefs" "github.com/docker/docker/errdefs"
"github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/container"
"github.com/docker/docker/integration/internal/process"
"github.com/docker/docker/pkg/stdcopy" "github.com/docker/docker/pkg/stdcopy"
"github.com/docker/docker/testutil/daemon" "github.com/docker/docker/testutil/daemon"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
@ -422,14 +422,21 @@ func testLiveRestoreAutoRemove(t *testing.T) {
t.Run("engine restart should remove containers that exited", func(t *testing.T) { t.Run("engine restart should remove containers that exited", func(t *testing.T) {
d, finishContainer, cID := run(t) d, finishContainer, cID := run(t)
apiClient := d.NewClientT(t)
// Get PID of the container process.
inspect, err := apiClient.ContainerInspect(ctx, cID)
assert.NilError(t, err)
pid := inspect.State.Pid
d.Stop(t) d.Stop(t)
finishContainer() finishContainer()
time.Sleep(time.Millisecond * 200) poll.WaitOn(t, process.NotAlive(pid))
d.Start(t, "--live-restore", "--iptables=false") d.Start(t, "--live-restore", "--iptables=false")
poll.WaitOn(t, container.IsRemoved(ctx, d.NewClientT(t), cID)) poll.WaitOn(t, container.IsRemoved(ctx, apiClient, cID))
}) })
} }

View file

@ -0,0 +1,17 @@
package process
import (
procpkg "github.com/docker/docker/pkg/process"
"gotest.tools/v3/poll"
)
// NotAlive verifies the process doesn't exist (finished or never started).
func NotAlive(pid int) func(log poll.LogT) poll.Result {
return func(log poll.LogT) poll.Result {
if !procpkg.Alive(pid) {
return poll.Success()
}
return poll.Continue("waiting for process to finish")
}
}