Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions crates/vt_bin/src/vtt/stalled_remote_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,42 @@ use std::{
sync::Arc,
};

/// stalled-remote-cache \[`--stall` `<route>`\]... `<command>` \[`<args>`...\]
/// stalled-remote-cache \[`--stall` `<route>`\]... \[`--milestone`\] `<command>` \[`<args>`...\]
///
/// Runs `<command>` with `VP_REMOTE_CACHE_URL` set to a loopback proxy for the
/// endpoint in `VP_REMOTE_CACHE_URL`, which must be
/// `http://<host>:<port>/<path>`, then exits with the command's exit code.
/// Requests to a stalled route below the endpoint, such as `/store`, are never
/// forwarded or answered: each emits a "stalled" milestone when it arrives,
/// and its connection is held until the client closes it. Other requests are
/// forwarded, each on its own connection. Ctrl-C is left to the command.
/// forwarded or answered: their connections are held until the client closes
/// them. Other requests are forwarded, each on its own connection. Ctrl-C is
/// left to the command.
///
/// On Windows a milestone is the console title, which `ConPTY` sends when it
/// With `--milestone`, each stalled request emits a "stalled" milestone when it
/// arrives. Leave it out when the test waits for a milestone from the command:
/// on Windows a milestone is the console title, which `ConPTY` sends when it
/// next renders, so if the command sets one at about the same time, the
/// earlier title can be lost.
pub fn run(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
let mut args = args;
let mut stalled_routes = Vec::new();
while let [flag, route, rest @ ..] = args
&& flag == "--stall"
{
stalled_routes.push(route.clone());
args = rest;
let mut milestone = false;
loop {
match args {
[flag, route, rest @ ..] if flag == "--stall" => {
stalled_routes.push(route.clone());
args = rest;
}
[flag, rest @ ..] if flag == "--milestone" => {
milestone = true;
args = rest;
}
_ => break,
}
}
let [program, args @ ..] = args else {
return Err(
"Usage: vtt stalled-remote-cache [--stall <route>]... <command> [args...]".into()
"Usage: vtt stalled-remote-cache [--stall <route>]... [--milestone] <command> [args...]"
.into(),
);
};
let upstream = std::env::var("VP_REMOTE_CACHE_URL")
Expand All @@ -41,6 +52,7 @@ pub fn run(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
upstream: authority.to_owned(),
base_path: std::format!("/{}", path.trim_end_matches('/')),
stalled_routes,
milestone,
});
ctrlc::set_handler(|| {})?;

Expand All @@ -67,6 +79,8 @@ struct Proxy {
base_path: String,
/// Routes below `base_path` whose requests stall.
stalled_routes: Vec<String>,
/// Whether a stalled request emits a "stalled" milestone.
milestone: bool,
}

impl Proxy {
Expand All @@ -83,7 +97,9 @@ impl Proxy {
.strip_prefix(self.base_path.as_str())
.is_some_and(|route| self.stalled_routes.iter().any(|stalled| stalled == route))
{
vt_pty_terminal_test_client::mark_milestone("stalled");
if self.milestone {
vt_pty_terminal_test_client::mark_milestone("stalled");
}
let mut buf = [0; 4096];
while client.read(&mut buf).is_ok_and(|n| n > 0) {}
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,6 @@ steps = [

[[e2e]]
name = "pending_uploads"
# Skipped on Windows, where a milestone is the console title and ConPTY sends
# only the latest one when it next renders: the proxy's `stalled` milestone for
# check's upload can replace `uploads-pending`.
cfg = "not(windows)"
ignore = true
steps = [
{ argv = [
Expand Down Expand Up @@ -522,6 +518,7 @@ steps = [
"stalled-remote-cache",
"--stall",
"/fetch",
"--milestone",
"vt",
"run",
"build",
Expand Down Expand Up @@ -615,9 +612,6 @@ steps = [

[[e2e]]
name = "hide_pending_uploads"
# Skipped on Windows, where a milestone is the console title and ConPTY sends
# it only when it next renders: nothing is printed after `uploads-pending`.
cfg = "not(windows)"
ignore = true
steps = [
{ argv = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ctrl_c_during_fetch

## `VP_REMOTE_CACHE_URL=http://127.0.0.1:0/projects/test vtt stalled-remote-cache --stall /fetch vt run build`
## `VP_REMOTE_CACHE_URL=http://127.0.0.1:0/projects/test vtt stalled-remote-cache --stall /fetch --milestone vt run build`

The proxy never answers the fetch, so nothing needs to listen behind it. Ctrl-C stops the fetch, and the task doesn't start.

Expand Down
Loading