mirror of
https://github.com/containers/podman.git
synced 2025-06-20 09:03:43 +08:00
Merge pull request #18912 from vrothberg/fix-18889
remote wait: fix "removed" condition
This commit is contained in:
@ -189,11 +189,21 @@ var notRunningStates = []define.ContainerStatus{
|
||||
}
|
||||
|
||||
func waitRemoved(ctrWait containerWaitFn) (int32, error) {
|
||||
code, err := ctrWait(define.ContainerStateUnknown)
|
||||
if err != nil && errors.Is(err, define.ErrNoSuchCtr) {
|
||||
return code, nil
|
||||
var code int32
|
||||
for {
|
||||
c, err := ctrWait(define.ContainerStateExited)
|
||||
if errors.Is(err, define.ErrNoSuchCtr) {
|
||||
// Make sure to wait until the container has been removed.
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return code, err
|
||||
}
|
||||
// If the container doesn't exist, the return code is -1, so
|
||||
// only set it in case of success.
|
||||
code = c
|
||||
}
|
||||
return code, err
|
||||
return code, nil
|
||||
}
|
||||
|
||||
func waitNextExit(ctx context.Context, containerName string) (int32, error) {
|
||||
|
@ -12,7 +12,8 @@ CTR="WaitTestingCtr"
|
||||
|
||||
t POST "containers/nonExistent/wait?condition=next-exit" 404
|
||||
|
||||
podman create --name "${CTR}" --entrypoint '["true"]' "${IMAGE}"
|
||||
# Make sure to test a non-zero exit code (see #18889)
|
||||
podman create --name "${CTR}" "${IMAGE}" sh -c "exit 3"
|
||||
|
||||
t POST "containers/${CTR}/wait?condition=non-existent-cond" 400
|
||||
|
||||
@ -24,7 +25,7 @@ child_pid=$!
|
||||
|
||||
# This will block until the background job completes
|
||||
t POST "containers/${CTR}/wait?condition=next-exit" 200 \
|
||||
.StatusCode=0 \
|
||||
.StatusCode=3 \
|
||||
.Error=null
|
||||
wait "${child_pid}"
|
||||
|
||||
@ -41,6 +42,10 @@ fi
|
||||
child_pid=$!
|
||||
|
||||
t POST "containers/${CTR}/wait?condition=removed" 200 \
|
||||
.StatusCode=0 \
|
||||
.StatusCode=3 \
|
||||
.Error=null
|
||||
# Make sure the container has really been removed after waiting for
|
||||
# "condition=removed". This check is racy but should flake in case it doesn't
|
||||
# work correctly.
|
||||
t POST "containers/${CTR}/wait?condition=next-exit" 404
|
||||
wait "${child_pid}"
|
||||
|
Reference in New Issue
Block a user