Skip to content

Commit

Permalink
test: More fixes to waiting for container restart
Browse files Browse the repository at this point in the history
 - Factor out the functionality into two helper methods, and use them in
   testPods as well. That had the same bugs as
   testLifecycleOperationsUser in commit 4ba8fc1.
 - The `Pid` field is "0" while the container is not running yet. So
   don't accept that.
 - Sleep in the waiting loop to avoid excessive polling.
  • Loading branch information
martinpitt committed Jul 5, 2023
1 parent 5c8d8f5 commit 3e0fb9c
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions test/check-application
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import os
import sys
import time

import testlib
from machine_core import ssh_connection
Expand Down Expand Up @@ -277,9 +278,21 @@ class TestApplication(testlib.MachineCase):
b.click(f"ul[aria-labelledby=pod-{podName}-{podOwner}-action-toggle] li > button.pod-action-{action.lower()}")
b.wait_not_present(f"ul[aria-labelledby=pod-{podName}-{podOwner}-action-toggle]")

def getPid(self, container: str, *, auth: bool) -> int:
out = self.execute(auth, "podman inspect --format '{{.State.Pid}}' " + container).strip()
return int(out)

def waitPidChange(self, container: str, old_pid: int, *, auth: bool) -> int:
for _ in range(10):
new_pid = self.getPid(container, auth=auth)
if new_pid != 0 and new_pid != old_pid:
return new_pid
time.sleep(1)
else:
self.fail("Timed out waiting for pid change")

def testPods(self):
b = self.browser
m = self.machine

self.login()

Expand Down Expand Up @@ -352,9 +365,9 @@ class TestApplication(testlib.MachineCase):
self.waitPodContainer("pod-1", [{"name": "test-pod-1-system", "image": IMG_ALPINE,
"command": "sleep 100", "state": "Running", "id": containerId}])

old_pid = m.execute("podman inspect --format '{{.State.Pid}}' test-pod-1-system")
old_pid = self.getPid("test-pod-1-system", auth=True)
self.performPodAction("pod-1", "system", "Restart")
b.wait(lambda: old_pid != m.execute("podman inspect --format '{{.State.Pid}}' test-pod-1-system".strip()))
self.waitPidChange("test-pod-1-system", old_pid, auth=True)

self.performPodAction("pod-1", "system", "Delete")
b.click(".pf-v5-c-modal-box button:contains(Delete)")
Expand Down Expand Up @@ -1212,15 +1225,10 @@ class TestApplication(testlib.MachineCase):

# Restart the container; there is no steady state change in the visible UI, so look for
# a changed data-pid attribute
old_pid = self.execute(auth, "podman inspect --format '{{.State.Pid}}' swamped-crate").strip()
old_pid = self.getPid("swamped-crate", auth=auth)
b.wait_in_text(f'#containers-containers tr[data-pid="{old_pid}"]', "swamped-crate")
self.performContainerAction(IMG_BUSYBOX, "Force restart")
for _ in range(10):
new_pid = self.execute(auth, "podman inspect --format '{{.State.Pid}}' swamped-crate").strip()
if new_pid and new_pid != old_pid:
break
else:
self.fail("Timed out waiting for pid change")
new_pid = self.waitPidChange("swamped-crate", old_pid, auth=auth)
b.wait_in_text(f'#containers-containers tr[data-pid="{new_pid}"]', "swamped-crate")
self.waitContainer(container_sha, auth, name='swamped-crate', image=IMG_BUSYBOX, state='Running')

Expand Down

0 comments on commit 3e0fb9c

Please sign in to comment.