mirror of
https://github.com/containers/podman.git
synced 2025-06-21 01:19:15 +08:00
Merge pull request #18912 from vrothberg/fix-18889
remote wait: fix "removed" condition
This commit is contained in:
@ -189,12 +189,22 @@ var notRunningStates = []define.ContainerStatus{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func waitRemoved(ctrWait containerWaitFn) (int32, error) {
|
func waitRemoved(ctrWait containerWaitFn) (int32, error) {
|
||||||
code, err := ctrWait(define.ContainerStateUnknown)
|
var code int32
|
||||||
if err != nil && errors.Is(err, define.ErrNoSuchCtr) {
|
for {
|
||||||
return code, nil
|
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
|
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, nil
|
||||||
|
}
|
||||||
|
|
||||||
func waitNextExit(ctx context.Context, containerName string) (int32, error) {
|
func waitNextExit(ctx context.Context, containerName string) (int32, error) {
|
||||||
runtime := ctx.Value(api.RuntimeKey).(*libpod.Runtime)
|
runtime := ctx.Value(api.RuntimeKey).(*libpod.Runtime)
|
||||||
|
@ -12,7 +12,8 @@ CTR="WaitTestingCtr"
|
|||||||
|
|
||||||
t POST "containers/nonExistent/wait?condition=next-exit" 404
|
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
|
t POST "containers/${CTR}/wait?condition=non-existent-cond" 400
|
||||||
|
|
||||||
@ -24,7 +25,7 @@ child_pid=$!
|
|||||||
|
|
||||||
# This will block until the background job completes
|
# This will block until the background job completes
|
||||||
t POST "containers/${CTR}/wait?condition=next-exit" 200 \
|
t POST "containers/${CTR}/wait?condition=next-exit" 200 \
|
||||||
.StatusCode=0 \
|
.StatusCode=3 \
|
||||||
.Error=null
|
.Error=null
|
||||||
wait "${child_pid}"
|
wait "${child_pid}"
|
||||||
|
|
||||||
@ -41,6 +42,10 @@ fi
|
|||||||
child_pid=$!
|
child_pid=$!
|
||||||
|
|
||||||
t POST "containers/${CTR}/wait?condition=removed" 200 \
|
t POST "containers/${CTR}/wait?condition=removed" 200 \
|
||||||
.StatusCode=0 \
|
.StatusCode=3 \
|
||||||
.Error=null
|
.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}"
|
wait "${child_pid}"
|
||||||
|
Reference in New Issue
Block a user