Fix flaky test (#4672)

This issue was due to the fact that the timeout is not always sufficient
to have enough character for truncation + a race between synthetic
timeout and process kill
This commit is contained in:
jif-oai
2025-10-03 18:09:41 +01:00
committed by GitHub
parent e0b38bd7a2
commit bfe3328129

View File

@@ -414,12 +414,15 @@ async fn shell_timeout_includes_timeout_prefix_and_metadata() -> Result<()> {
.find(|item| item.get("call_id").and_then(Value::as_str) == Some(call_id)) .find(|item| item.get("call_id").and_then(Value::as_str) == Some(call_id))
.expect("timeout output present"); .expect("timeout output present");
let output_json: Value = serde_json::from_str( let output_str = timeout_item
timeout_item
.get("output") .get("output")
.and_then(Value::as_str) .and_then(Value::as_str)
.expect("timeout output string"), .expect("timeout output string");
)?;
// The exec path can report a timeout in two ways depending on timing:
// 1) Structured JSON with exit_code 124 and a timeout prefix (preferred), or
// 2) A plain error string if the child is observed as killed by a signal first.
if let Ok(output_json) = serde_json::from_str::<Value>(output_str) {
assert_eq!( assert_eq!(
output_json["metadata"]["exit_code"].as_i64(), output_json["metadata"]["exit_code"].as_i64(),
Some(124), Some(124),
@@ -441,10 +444,17 @@ async fn shell_timeout_includes_timeout_prefix_and_metadata() -> Result<()> {
duration_ms >= timeout_ms, duration_ms >= timeout_ms,
"expected duration >= configured timeout, got {duration_ms} (timeout {timeout_ms})" "expected duration >= configured timeout, got {duration_ms} (timeout {timeout_ms})"
); );
} else {
// Fallback: accept the signal classification path to deflake the test.
assert!( assert!(
stdout.contains("[... omitted"), output_str.contains("execution error"),
"expected truncated output marker, got {stdout:?}" "unexpected non-JSON output: {output_str:?}"
); );
assert!(
output_str.contains("Signal(") || output_str.to_lowercase().contains("signal"),
"expected signal classification in error output, got {output_str:?}"
);
}
Ok(()) Ok(())
} }