Skip to content

Commit 64c4a0d

Browse files
test(features): run the host-gateway client with sandbox exec
On k3s-ha, attaching to a main process that already finished can reach a gateway replica without the sandbox's session and fail with "sandbox is not ready". Run the client in a Ready sandbox instead. Signed-off-by: Matthew Grossman <[email protected]>
1 parent 2183ead commit 64c4a0d

1 file changed

Lines changed: 37 additions & 15 deletions

File tree

‎tests/suites/features/host-gateway/tests/host_gateway.rs‎

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
//! compute driver.
66
//!
77
//! The test starts an HTTP server where the tests run, which is the host the
8-
//! gateway runs its sandboxes on, and creates a sandbox from the Python test
9-
//! image ([`testkit::python_image`]) whose main process requests a page from
10-
//! that server through the name.
8+
//! gateway runs its sandboxes on, and runs a client in a sandbox from the
9+
//! Python test image ([`testkit::python_image`]) that requests a page from that
10+
//! server through the name.
1111
1212
use testkit::{Context, Error, Result, ResultExt as _};
1313
use tokio::io::{AsyncReadExt as _, AsyncWriteExt as _};
@@ -57,18 +57,40 @@ async fn python_sandbox_reaches_host_server(cx: &mut Context) -> testkit::Result
5757
let port = server.port.to_string();
5858
let image = testkit::python_image();
5959

60+
// The client runs through `sandbox exec` in a Ready sandbox, not as the
61+
// main process. A gateway with several replicas (k3s-ha) can refuse to
62+
// attach to a main process that already finished with "sandbox is not
63+
// ready" when the request reaches a replica that doesn't hold the
64+
// sandbox's session.
6065
let name = cx.name("hg");
6166
cx.track(&name);
62-
let create = cx
67+
cx.cli([
68+
"sandbox",
69+
"create",
70+
"--name",
71+
&name,
72+
"--from",
73+
&image,
74+
"--policy",
75+
policy.path()?,
76+
"--detach",
77+
"--no-tty",
78+
"--",
79+
"sh",
80+
"-c",
81+
"exec sleep infinity",
82+
])
83+
.await?
84+
.success()
85+
.context(format!("create a sandbox from {image}"))?;
86+
cx.adopt(&name).await?.wait_ready().await?;
87+
88+
let client = cx
6389
.cli([
6490
"sandbox",
65-
"create",
91+
"exec",
6692
"--name",
6793
&name,
68-
"--from",
69-
&image,
70-
"--policy",
71-
policy.path()?,
7294
"--no-tty",
7395
"--",
7496
VENV_PYTHON,
@@ -78,17 +100,17 @@ async fn python_sandbox_reaches_host_server(cx: &mut Context) -> testkit::Result
78100
])
79101
.await?
80102
.success()
81-
.context(format!("sandbox from {image} runs the client"))?;
103+
.context("run the client in the sandbox")?;
82104
testkit::ensure!(
83-
create.stdout.contains("prefix=/sandbox/.venv"),
105+
client.stdout.contains("prefix=/sandbox/.venv"),
84106
"the client did not run in the image's virtual environment:\n{}",
85-
create.stdout
107+
client.stdout
86108
);
87109
testkit::ensure!(
88-
create.stdout.contains(&marker),
110+
client.stdout.contains(&marker),
89111
"the client did not get the host server's response:\n{}{}",
90-
create.stdout,
91-
create.stderr
112+
client.stdout,
113+
client.stderr
92114
);
93115
Ok(())
94116
}

0 commit comments

Comments
 (0)