Skip to content

Commit 1bc0087

Browse files
authored
[core] improve assertion check in test_task_metrics (ray-project#53958)
I'm investigating the flakiness of test_task_metrics on Windows. Currently, when the test fails, it logs only a generic error message (see [build log](https://buildkite.com/ray-project/postmerge/builds/10962/steps/canvas?jid=019788f1-08fe-4509-a42e-85cd1f1b6e37#019788f1-08fe-4509-a42e-85cd1f1b6e37/1546-1688)), which makes debugging difficult. I'm replacing wait_for_condition with wait_for_assertion, a more informative alternative that logs the actual value being tested, making it easier to identify what went wrong. Test: -CI Signed-off-by: Cuong Nguyen <can@anyscale.com>
1 parent 6f4c704 commit 1bc0087

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

python/ray/tests/test_task_metrics.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
raw_metrics,
1313
run_string_as_driver,
1414
run_string_as_driver_nonblocking,
15+
wait_for_assertion,
1516
)
1617

1718

@@ -152,8 +153,14 @@ def f():
152153
"RUNNING_IN_RAY_GET": 1.0,
153154
"PENDING_NODE_ASSIGNMENT": 8.0,
154155
}
155-
wait_for_condition(
156-
lambda: tasks_by_state(info) == expected, timeout=20, retry_interval_ms=2000
156+
157+
def check_task_state():
158+
assert tasks_by_state(info) == expected
159+
160+
wait_for_assertion(
161+
check_task_state,
162+
timeout=20,
163+
retry_interval_ms=2000,
157164
)
158165
assert tasks_by_name_and_state(info) == {
159166
("wrapper", "RUNNING_IN_RAY_GET"): 1.0,
@@ -190,8 +197,14 @@ def f():
190197
"RUNNING_IN_RAY_WAIT": 1.0,
191198
"PENDING_NODE_ASSIGNMENT": 8.0,
192199
}
193-
wait_for_condition(
194-
lambda: tasks_by_state(info) == expected, timeout=20, retry_interval_ms=2000
200+
201+
def check_task_state():
202+
assert tasks_by_state(info) == expected
203+
204+
wait_for_assertion(
205+
check_task_state,
206+
timeout=20,
207+
retry_interval_ms=2000,
195208
)
196209
assert tasks_by_name_and_state(info) == {
197210
("wrapper", "RUNNING_IN_RAY_WAIT"): 1.0,

0 commit comments

Comments
 (0)