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>
This commit is contained in:
parent
c5ea3d595c
commit
3a0af5ad30
2 changed files with 27 additions and 3 deletions
|
@ -13,7 +13,6 @@ import (
|
|||
"strings"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
|
@ -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"
|
||||
"github.com/docker/docker/testutil/daemon"
|
||||
|
@ -433,14 +433,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")
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue