Skip to content

Commit 5f4c2d9

Browse files
camillobruniV8 LUCI CQ
authored andcommitted
Improve wait_js_condition and WaitRange doc
- Rename min_wait to min_interval in wait_js_condition - Add better documentation to wait_js_condition - Set 0 as default value for delay Change-Id: Ic083f8ebfb92f3758dfa18d4f09de0a63320d89e Reviewed-on: https://chromium-review.googlesource.com/c/crossbench/+/6650992 Reviewed-by: Patrick Thier <[email protected]> Commit-Queue: Camillo Bruni <[email protected]>
1 parent 749d1a4 commit 5f4c2d9

File tree

13 files changed

+51
-27
lines changed

13 files changed

+51
-27
lines changed

crossbench/action_runner/default_action_runner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def _or_more_match(js_result: int) -> bool:
244244
try:
245245
actions.wait_js_condition(
246246
selector_script,
247-
min_wait=0.2,
247+
min_interval=0.2,
248248
timeout=timeout,
249249
arguments=(selector,),
250250
success_condition=success_condition)
@@ -269,7 +269,7 @@ def wait_for_condition(self, run: Run,
269269
action: i_action.WaitForConditionAction) -> None:
270270
with run.actions("WaitForConditionAction", measure=False) as actions:
271271
actions.wait_js_condition(
272-
action.condition, min_wait=0.1, timeout=action.timeout)
272+
action.condition, min_interval=0.1, timeout=action.timeout)
273273

274274
@override
275275
def wait_for_ready_state(self, run: Run,
@@ -379,7 +379,7 @@ def wait_for_download(self, run: Run,
379379
f"{repr(self.info_stack)}")
380380
assert isinstance(ctx, DownloadsProbeContext)
381381

382-
wait_range = run.wait_range(min_wait=0.2, timeout=action.timeout, delay=0)
382+
wait_range = run.wait_range(min_interval=0.2, timeout=action.timeout)
383383
for _ in wait_range.wait_with_backoff():
384384
if ctx.download_complete(action.pattern):
385385
return

crossbench/benchmarks/jetstream/jetstream_1_1.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ def setup(self, run: Run) -> None:
9696
url=self.get_run_url(run),
9797
ready_state=ReadyState.COMPLETE,
9898
timeout=dt.timedelta(seconds=10))
99-
actions.wait_js_condition("return !!JetStream;", min_wait=0.01, timeout=2)
99+
actions.wait_js_condition(
100+
"return !!JetStream;", min_interval=0.01, timeout=2)
100101
actions.js("JetStream.initialize();")
101102
# Intercept console.log to capture the raw results.
102103
actions.js("""
@@ -121,7 +122,7 @@ def run_wait_until_done(self, run: Run) -> None:
121122
return (summaryElement.innerHTML.indexOf("Score") >= 0);
122123
""",
123124
0.5,
124-
self.slow_duration,
125+
timeout=self.slow_duration,
125126
delay=self.substory_duration)
126127

127128

crossbench/benchmarks/jetstream/jetstream_2.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ def setup(self, run: Run) -> None:
142142
timeout=dt.timedelta(seconds=10))
143143
if self._substories != self.SUBSTORIES:
144144
actions.wait_js_condition(
145-
"return globalThis?.JetStream?.benchmarks?.length > 0;", 0.1, 10)
145+
"return globalThis?.JetStream?.benchmarks?.length > 0;",
146+
0.1,
147+
timeout=10)
146148
actions.js(
147149
"""
148150
let benchmarks = arguments[0];
@@ -153,7 +155,9 @@ def setup(self, run: Run) -> None:
153155
actions.wait_js_condition(
154156
"""
155157
return document.querySelectorAll("#results>.benchmark").length > 0;
156-
""", 1, self.duration + dt.timedelta(seconds=30))
158+
""",
159+
1,
160+
timeout=self.duration + dt.timedelta(seconds=30))
157161

158162

159163
ProbeClsTupleT = tuple[Type[JetStream2Probe], ...]

crossbench/benchmarks/loading/config/login/google.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ def _submit_login_field(self, action: Actions, secret: UsernamePassword,
9595
action.wait_js_condition(
9696
("return "
9797
f"document.querySelector(\"[aria-label='{aria_label}']\") != null &&"
98-
f"document.getElementById({repr(button_name)}) != null;"), 0.2, 10)
98+
f"document.getElementById({repr(button_name)}) != null;"),
99+
0.2,
100+
timeout=10)
99101
action.js("const inputField ="
100102
f" document.querySelector(\"[aria-label='{aria_label}']\");"
101103
f"inputField.value = {repr(input_val)};"
@@ -129,8 +131,7 @@ def run_with(self, runner: ActionRunner, run: Run,
129131
self.timeout(secret))
130132
action.wait_for_ready_state(ReadyState.COMPLETE, self.timeout(secret))
131133

132-
wait_range = run.wait_range(0.2, self.timeout(secret), 0)
133-
134+
wait_range = run.wait_range(0.2, self.timeout(secret))
134135
for _, _, time_left in wait_range.wait_with_backoff():
135136
current_url = action.current_url()
136137

crossbench/benchmarks/motionmark/motionmark_1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ def run(self, run: Run) -> None:
305305
return window.benchmarkRunnerClient.results._results != undefined
306306
""",
307307
0.5,
308-
self.slow_duration,
308+
timeout=self.slow_duration,
309309
delay=self.substory_duration / 4)
310310

311311

crossbench/benchmarks/speedometer/speedometer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ def setup(self, run: Run) -> None:
197197
updated_url = self.get_run_url(run)
198198
with run.actions("Setup") as actions:
199199
actions.show_url(updated_url)
200-
actions.wait_js_condition("return window.Suites !== undefined;", 0.5, 10)
200+
actions.wait_js_condition(
201+
"return window.Suites !== undefined;", 0.5, timeout=10)
201202
self._setup_substories(actions)
202203
self._setup_benchmark_client(actions)
203204
actions.wait(0.5)
@@ -257,7 +258,7 @@ def run(self, run: Run) -> None:
257258
actions.wait_js_condition(
258259
"return window.testDone",
259260
0.5,
260-
self.slow_duration,
261+
timeout=self.slow_duration,
261262
delay=self.substory_duration)
262263

263264

crossbench/plt/posix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ def popen(self,
556556
self, host_platform_cmd, bufsize=bufsize, stdout=stdout,
557557
stderr=stderr, stdin=stdin)
558558
# tmp_pid_file might not have been immediately flushed:
559-
for _ in WaitRange(0.01, 2).wait_with_backoff():
559+
for _ in WaitRange(0.01, timeout=2).wait_with_backoff():
560560
if pid_str := self.cat(temp_pid_file):
561561
remote_pid = int(pid_str)
562562
remote_popen.set_remote_pid(remote_pid)

crossbench/probes/chrome_histograms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ def dump_histograms(self, name: str) -> dict[str, ChromeHistogramSample]:
380380
ready_state=ReadyState.COMPLETE,
381381
timeout=dt.timedelta(seconds=10))
382382
actions.js(self.HISTOGRAM_SEND)
383-
actions.wait_js_condition(self.HISTOGRAM_WAIT, 0.1, 10.0)
383+
actions.wait_js_condition(self.HISTOGRAM_WAIT, 0.1, timeout=10.0)
384384
data = actions.js(self.HISTOGRAM_DATA)
385385
histogram_list = ObjectParser.sequence(data)
386386
histograms: dict[str, ChromeHistogramSample] = {}

crossbench/probes/perfetto/perfetto.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def _stop_perfetto(self) -> None:
244244
# TODO(cbruni): replace with terminate_gracefully
245245
self.browser_platform.terminate(self._perfetto_pid)
246246
try:
247-
for _ in WaitRange(1, 30).wait_with_backoff():
247+
for _ in WaitRange(1, timeout=30).wait_with_backoff():
248248
if not self.browser_platform.process_info(self._perfetto_pid):
249249
break
250250
except TimeoutError:

crossbench/runner/actions.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from crossbench import plt
2323
from crossbench.browsers.browser import Browser
2424
from crossbench.exception import ExceptionAnnotationScope
25+
from crossbench.helper.wait import WaitRange
2526
from crossbench.runner.run import Run
2627
from crossbench.runner.runner import Runner
2728
from crossbench.runner.timing import AnyTimeUnit, Timing
@@ -117,14 +118,24 @@ def js(self,
117118
def wait_js_condition(
118119
self,
119120
js_code: str,
120-
min_wait: AnyTimeUnit,
121+
min_interval: AnyTimeUnit,
121122
timeout: AnyTimeUnit,
122123
delay: AnyTimeUnit = 0,
123124
absolute_time: bool = False,
124125
arguments: Sequence[object] = (),
125126
success_condition: Callable[[Any], bool] = _default_success_condition
126127
) -> None:
127-
wait_range = self._run.wait_range(min_wait, timeout, delay)
128+
"""
129+
Runs the `js_code` at a regular interval until either the `timeout` is
130+
reached or the return value is true. The poll interval is exponentially
131+
increasing with the WaitRange's default factor:
132+
1. sleep for `delay`, check `js_code`
133+
2. sleep for `min_interval`, check `js_code`
134+
2. sleep for `min_interval * 1.01 ** 1`, check `js_code`
135+
...
136+
N. sleep for `min_interval * 1.01 ** N`, check `js_code`
137+
"""
138+
wait_range : WaitRange = self._run.wait_range(min_interval, timeout, delay)
128139
assert "return" in js_code, (
129140
f"Missing return statement in js-wait code: {js_code}")
130141
for _, _, time_left in wait_range.wait_with_backoff():
@@ -145,7 +156,7 @@ def wait_for_ready_state(self, ready_state: ReadyState,
145156
f"""
146157
let state = document.readyState;
147158
return state === '{ready_state}' || state === "complete";
148-
""", 0.2, timeout.total_seconds())
159+
""", 0.2, timeout)
149160

150161
def show_url(
151162
self,

0 commit comments

Comments
 (0)