aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--idatui/worker_client.py25
-rw-r--r--tests/test_project_ui.py29
2 files changed, 38 insertions, 16 deletions
diff --git a/idatui/worker_client.py b/idatui/worker_client.py
index 4f90700..173cd9d 100644
--- a/idatui/worker_client.py
+++ b/idatui/worker_client.py
@@ -117,16 +117,20 @@ class WorkerClient:
# (a small binary, or a seeded .i64), which is most of the time in
# the tests and noticeable on a re-open.
#
- # Backing off geometrically from the first probe was still too eager:
- # a seeded database is ready at ~250ms, by which point the delay has
- # grown to 134ms, so every open waited ~350ms whatever the binary --
- # the same number for a 47KB `echo` and a 1.2MB `bash`, which is what
- # gives a polling artefact away. Hold the fast rate for the first few
- # seconds (a connect attempt on an absent socket is microseconds) and
- # only slow down for a genuine cold auto-analysis, which runs for
- # minutes and does not care about 200ms.
+ # Backing off all the way to 0.2s was too eager: a seeded database
+ # is ready at ~250ms, by which point the delay has grown to 134ms, so
+ # every open waited ~350ms whatever the binary -- the same number for
+ # a 47KB `echo` and a 1.2MB `bash`, which is what gives a polling
+ # artefact away. Cap the backoff at 25ms instead: the overshoot on a
+ # fast open is bounded by that, and 40 probes a second is nothing
+ # next to an auto-analysis that runs for minutes.
+ #
+ # Do NOT be tempted to hold the 5ms rate instead. This poll runs on a
+ # background thread while the UI thread is drawing, and 200 wakeups a
+ # second through a cold analysis cost enough GIL time to delay the
+ # app's own startup -- it left the loading overlay up long enough for
+ # project mode's first keypress to land on it.
delay = 0.005
- fast_until = t0 + 5.0
while time.time() < deadline:
try:
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
@@ -142,8 +146,7 @@ class WorkerClient:
progress(f"auto-analyzing {os.path.basename(self._bin)}… "
f"({int(time.time() - t0)}s)")
time.sleep(delay)
- if time.time() > fast_until:
- delay = min(delay * 1.6, 0.2)
+ delay = min(delay * 1.6, 0.025)
raise IDAConnectionError("worker did not become ready in time")
@property
diff --git a/tests/test_project_ui.py b/tests/test_project_ui.py
index 753717a..7e93c81 100644
--- a/tests/test_project_ui.py
+++ b/tests/test_project_ui.py
@@ -56,10 +56,27 @@ async def run(bins):
async def settle(pred, t=180.0):
return await wait_for(pred, pilot.pause, t, 0.05)
+ async def usable(t=180.0):
+ """Loaded AND drivable.
+
+ An index that has finished streaming does not mean the app is
+ taking keys yet: the loading overlay is a ModalScreen and it is
+ dismissed a moment later, by auto-land. Between those two the
+ app looks ready and swallows every keypress -- so a test that
+ waits only for the index presses Ctrl+O into the overlay and
+ sees no switcher. Which side of that gap the poll lands on is
+ decided by how fast the backend happens to be, so it has to be
+ waited for explicitly, not hoped for.
+ """
+ return await settle(
+ lambda: app.program is not None
+ and app._func_index is not None
+ and app._func_index.complete
+ and app._loading_screen is None
+ and len(app.screen_stack) == 1, t)
+
# -- boots on the project's first binary ----------------------- #
- ok = await settle(lambda: app.program is not None
- and app._func_index is not None
- and app._func_index.complete)
+ ok = await usable()
check("project mode boots on the first binary", ok,
f"binary={app._binary}")
check("the active binary is the first one", app._binary == first,
@@ -100,7 +117,8 @@ async def run(bins):
await pilot.press("enter")
switched = await settle(
lambda: app._binary == second and app.program is not None
- and app._func_index is not None and app._func_index.complete)
+ and app._func_index is not None and app._func_index.complete
+ and len(app.screen_stack) == 1)
check("switching opens the other binary", switched,
f"binary={app._binary}")
check("the second binary has its own function index",
@@ -127,7 +145,8 @@ async def run(bins):
await pilot.press("enter")
back = await settle(lambda: app._binary == first
and app._func_index is not None
- and app._func_index.complete, 120)
+ and app._func_index.complete
+ and len(app.screen_stack) == 1, 120)
check("switching back returns to the first binary", back,
f"binary={app._binary}")
check("its function index came back intact",