Skip to content

Commit ebf8b9d

Browse files
committed
fix(tests): make test more reliable
Signed-off-by: Gordon Sim <[email protected]>
1 parent 011775e commit ebf8b9d

1 file changed

Lines changed: 39 additions & 21 deletions

File tree

‎e2e/rust/tests/podman_host_gateway.rs‎

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,44 @@ fn podman_container_diagnostics(sandbox_name: &str) -> String {
7676
}
7777

7878
async fn assert_host_gateway_reachable(sandbox: &SandboxGuard, port: u16, stage: &str) {
79-
let command = format!(
80-
"exec 3<>/dev/tcp/host.openshell.internal/{port}; \
81-
printf 'GET / HTTP/1.1\\r\\nHost: host.openshell.internal:{port}\\r\\nConnection: close\\r\\n\\r\\n' >&3; \
82-
while IFS= read -r line <&3; do [ \"$line\" = $'\\r' ] && break; done; \
83-
IFS= read -r body <&3; printf '%s' \"$body\""
84-
);
85-
let output = match tokio::time::timeout(
86-
Duration::from_secs(30),
87-
sandbox.exec(&["/usr/bin/bash", "-c", &command]),
88-
)
89-
.await
90-
{
91-
Ok(Ok(output)) => output,
79+
let url = format!("http://host.openshell.internal:{port}/");
80+
let probe = async {
81+
let mut failures = Vec::new();
82+
for attempt in 1..=5 {
83+
match sandbox
84+
.exec(&[
85+
"/usr/bin/curl",
86+
"--fail",
87+
"--silent",
88+
"--show-error",
89+
"--noproxy",
90+
"*",
91+
"--connect-timeout",
92+
"2",
93+
"--max-time",
94+
"5",
95+
&url,
96+
])
97+
.await
98+
{
99+
Ok(output) if output.contains(RESPONSE) => return Ok(()),
100+
Ok(output) => failures.push(format!(
101+
"attempt {attempt} returned an unexpected response:\n{output}"
102+
)),
103+
Err(err) => failures.push(format!("attempt {attempt} failed: {err}")),
104+
}
105+
106+
if attempt < 5 {
107+
tokio::time::sleep(Duration::from_secs(1)).await;
108+
}
109+
}
110+
Err(failures.join("\n"))
111+
};
112+
113+
match tokio::time::timeout(Duration::from_secs(40), probe).await {
114+
Ok(Ok(())) => {}
92115
Ok(Err(err)) => panic!(
93-
"host gateway probe failed during {stage}: {err}\n{}",
116+
"host gateway probe failed during {stage} after bounded retries:\n{err}\n{}",
94117
podman_container_diagnostics(&sandbox.name)
95118
),
96119
Err(_) => {
@@ -100,12 +123,7 @@ async fn assert_host_gateway_reachable(sandbox: &SandboxGuard, port: u16, stage:
100123
podman_container_diagnostics(&sandbox.name)
101124
);
102125
}
103-
};
104-
assert!(
105-
output.contains(RESPONSE),
106-
"sandbox did not receive the host response during {stage}:\n{output}\n{}",
107-
podman_container_diagnostics(&sandbox.name)
108-
);
126+
}
109127
}
110128

111129
#[tokio::test]
@@ -160,7 +178,7 @@ network_policies:
160178
port: {port}
161179
protocol: tcp
162180
binaries:
163-
- path: /usr/bin/bash
181+
- path: /usr/bin/curl
164182
"
165183
),
166184
)

0 commit comments

Comments
 (0)