Skip to content

Commit 955885b

Browse files
committed
charm/tests/retracer: remove magic sleep and use retry loop instead
1 parent 593961c commit 955885b

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

charm/tests/integration/test_retracer.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
2-
import time
32

43
import jubilant
4+
from tenacity import Retrying, stop_after_attempt, wait_exponential
55
from utils import check_config
66

77
logger = logging.getLogger()
@@ -72,18 +72,21 @@ def test_deploy(
7272
"00000000-1111-4222-3333-444444444444:swift",
7373
unit="rabbitmq-server/0",
7474
)
75-
# Give some arbitrary time to process.
76-
# For now I'm taking that cursed path, and depending on how flaky this
77-
# becomes, I'll see later to implement a wait loop.
78-
time.sleep(4)
79-
80-
# Verify that the retracer didn't Traceback and processed the sent crash
81-
task = juju.exec("journalctl", "-u", "retracer@amd64.service", unit="retracer/0")
82-
retracer_logs = task.stdout
83-
assert "Waiting for messages in `retrace_amd64`" in retracer_logs, (
84-
"retracer didn't reach waiting on amqp"
85-
)
86-
assert (
87-
"00000000-1111-4222-3333-444444444444:swift:Failed to decompress core: Error -3 while decompressing data: incorrect header check"
88-
in retracer_logs
89-
), "retracer didn't try to decompress the core. Either `swift` or `amqp` is broken."
75+
# Let give this test a few chances to succeed, as it can sometimes be a bit
76+
# slow to process the crash
77+
for attempt in Retrying(
78+
stop=stop_after_attempt(5),
79+
wait=wait_exponential(min=5, max=30),
80+
reraise=True,
81+
):
82+
with attempt:
83+
# Verify that the retracer didn't Traceback and processed the sent crash
84+
task = juju.exec("journalctl", "-u", "retracer@amd64.service", unit="retracer/0")
85+
retracer_logs = task.stdout
86+
assert "Waiting for messages in `retrace_amd64`" in retracer_logs, (
87+
"retracer didn't reach waiting on amqp"
88+
)
89+
assert (
90+
"00000000-1111-4222-3333-444444444444:swift:Failed to decompress core: Error -3 while decompressing data: incorrect header check"
91+
in retracer_logs
92+
), "retracer didn't try to decompress the core. Either `swift` or `amqp` is broken."

0 commit comments

Comments
 (0)