mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
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:
@@ -14,7 +14,6 @@ import (
|
||||
"strings"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/mount"
|
||||
@@ -22,6 +21,7 @@ import (
|
||||
"github.com/docker/docker/daemon/config"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/integration/internal/container"
|
||||
"github.com/docker/docker/integration/internal/process"
|
||||
"github.com/docker/docker/pkg/stdcopy"
|
||||
"github.com/docker/docker/testutil/daemon"
|
||||
"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) {
|
||||
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)
|
||||
|
||||
finishContainer()
|
||||
time.Sleep(time.Millisecond * 200)
|
||||
poll.WaitOn(t, process.NotAlive(pid))
|
||||
|
||||
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))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
17
integration/internal/process/wait.go
Normal file
17
integration/internal/process/wait.go
Normal 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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user