aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authoruser <user@clank>2026-08-16 16:25:36 +0200
committeruser <user@clank>2026-08-16 16:25:36 +0200
commit814a2e52757060237e8354f138dc3e4e3d13fd90 (patch)
tree61bed6123c1aba1182678345dcd4c3b67b1ca1ff /tests
parentsl0ppty: two tests that were sampling, not asking (diff)
downloadslosh-814a2e52757060237e8354f138dc3e4e3d13fd90.tar.gz
slosh-814a2e52757060237e8354f138dc3e4e3d13fd90.tar.xz
slosh-814a2e52757060237e8354f138dc3e4e3d13fd90.zip
sl0ppty: a race in the reload test, caught at one in eight
`test_a_config_written_after_the_session_started_is_noticed` starts a session whose config directory does not exist, then writes a config into it. The session is what *creates* that directory -- the whole point of the test is that a file appearing later gets noticed -- and `sl0ppty -s` returning means the session was asked for, not that it has got that far. So the write could land first, and did: FileNotFoundError: /tmp/sl0ppty-home-rl_q8peu/.config/sl0ppty/config.kdl Once in about eight full-suite runs, never on its own, never under load I could synthesise -- which is why it took ten runs in a row to catch and why it has been sitting there since the watcher work. Nothing to do with what is around it in this branch; found because I was hunting a flake I had caused elsewhere and this one answered instead. Fixed by waiting for the directory, which turns the thing the test *depended* on into something it *states*: "the session created the directory it needs to watch". The include test's startup check is polled for the same reason, since it too read a screen the session had not necessarily drawn yet. Verified the only way this kind of thing can be: ten consecutive clean runs of the whole suite, and the file's own eleven checks green in isolation.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_reload.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/tests/test_reload.py b/tests/test_reload.py
index 8e7b35a..ce40cdc 100644
--- a/tests/test_reload.py
+++ b/tests/test_reload.py
@@ -102,6 +102,21 @@ def test_a_config_written_after_the_session_started_is_noticed():
name = "reloadtest-%d" % os.getpid()
subprocess.run([BIN, "-s", name, "--", "/bin/sh", "-c", "read x"],
env=env, capture_output=True, timeout=5)
+
+ # The session *creates* its config directory at startup, precisely so there is
+ # always somewhere to watch -- and writing the file before it has is a race
+ # this test lost about once in eight full-suite runs, under load, with a
+ # FileNotFoundError from the open() below. Waiting for it turns the thing the
+ # test depends on into something the test states.
+ made = None
+ dir_deadline = time.time() + 3
+ while time.time() < dir_deadline:
+ if os.path.isdir(os.path.dirname(path)):
+ made = True
+ break
+ time.sleep(0.02)
+ check("the session created the directory it needs to watch", made,
+ os.path.dirname(path))
try:
deadline = time.time() + 3
got = None
@@ -148,7 +163,16 @@ def test_an_included_file_is_watched_too():
capture_output=True, text=True, env=env).stdout
try:
- check("the included theme applied at startup", '"#00ff00"' in screen(),
+ # Polled for the same reason as the directory above: `-s` returning means
+ # the session was asked for, not that it has composed a frame to look at.
+ started = None
+ deadline = time.time() + 3
+ while time.time() < deadline:
+ if '"#00ff00"' in screen():
+ started = True
+ break
+ time.sleep(0.02)
+ check("the included theme applied at startup", started,
"green never appeared")
# The include line is untouched; only the file it points at changes.