forge
Explore
Log in

Don't you dare go Hollow

CI claims wait a configurable time, and the e2e tests set it small

Browse files at this commit

f6cbcece6d956ff75b3415bb8a034fba0267a0c2Ahmet Kaan GümüşParent: 9b3e6a7
  • perf
    • CI claims wait a configurable time, and the e2e tests set it small
Show full message
⚡ perf: CI claims wait a configurable time, and the e2e tests set it small

The e2e drain loop claims until the forge has nothing left, and that last
claim always sat out the full 25 s claim long poll. Two drains cost the fork
test 50 s, one drain cost the push and merge queue tests about 25 s each.

The claim wait is now `[ci] claim_wait_ms` (default 25000, unchanged in
production). The e2e servers set it to 50, and the unit-test config does the
same. The live log test drops its fixed `sleep 5` for a release file the test
writes after it sees the first line, so the job still runs while the stream
is read, and the wait is only as long as the job needs.

Timings (nextest, same machine, under shared CPU load):
  fork_pull_waits_for_approval_and_runs_without_secrets  59.6 s -> 6.0 s
  push_run_masks_secrets_keeps_artifacts_and_skips_dependants  33.1 s -> 4.8 s
  merge_queue_lands_the_first_pull_and_kicks_out_the_conflicting_second  34.0 s -> 6.2 s
  live_log_streams_until_the_job_finishes  9.7 s -> 4.8 s

All assertions are unchanged.
crates/forge-core/src/config.rsmodified+3 -0
@@ -342,6 +342,8 @@ pub struct CiConfig {
342342 pub artifact_retention_days: u64,
343343 /// Hours a runner registration token stays valid.
344344 pub registration_token_hours: u32,
345+ /// Milliseconds a runner claim waits for work before it is answered with no job.
346+ pub claim_wait_ms: u64,
345347 }
346348
347349 impl Default for CiConfig {
@@ -354,6 +356,7 @@ impl Default for CiConfig {
354356 log_retention_days: 90,
355357 artifact_retention_days: 30,
356358 registration_token_hours: 24,
359+ claim_wait_ms: 25_000,
357360 }
358361 }
359362 }
crates/forge-web/src/ci/api.rsmodified+3 -7
@@ -42,11 +42,6 @@ const LOG_SIZE_HEADER: &str = "x-forge-log-size";
4242 const MAX_LOG_CHUNK: usize = 1024 * 1024;
4343 /// Largest JSON body on the runner routes, in bytes.
4444 const MAX_JSON_BODY: usize = 64 * 1024;
45-/// How long a claim waits for work before answering 204.
46-#[cfg(not(test))]
47-const CLAIM_WAIT: std::time::Duration = std::time::Duration::from_secs(25);
48-#[cfg(test)]
49-const CLAIM_WAIT: std::time::Duration = std::time::Duration::from_millis(50);
5045 /// What the forge assumes a runner reserves for a job with no `memory`, when the runner did not say.
5146 const DEFAULT_RESERVE: u64 = 1 << 30;
5247 /// Longest runner name or label, in bytes.
@@ -343,9 +338,10 @@ async fn claim_work(
343338 ) -> topcoat::Result<Response> {
344339 // Arm the wake-up before each attempt, so a job queued during the attempt is not missed.
345340 // Producers use notify_waiters, which wakes every claimer, so a runner whose labels
346- // don't match a job re-arms and keeps waiting for the rest of CLAIM_WAIT.
341+ // don't match a job re-arms and keeps waiting for the rest of the claim wait.
347342 let waker = state.ci_waker.clone();
348- let deadline = tokio::time::Instant::now() + CLAIM_WAIT;
343+ let wait = std::time::Duration::from_millis(state.config.ci.claim_wait_ms);
344+ let deadline = tokio::time::Instant::now() + wait;
349345 loop {
350346 let mut woken = std::pin::pin!(waker.notified());
351347 woken.as_mut().enable();
crates/forge-web/src/test_support.rsmodified+6 -1
@@ -7,6 +7,7 @@ use std::path::Path;
77 use std::sync::Arc;
88 use std::time::Duration;
99
10+use forge_core::config::CiConfig;
1011 use forge_core::time::stamp_after;
1112 use forge_core::token::hash_token;
1213 use forge_core::{Config, Registration, Store};
@@ -48,7 +49,11 @@ pub fn test_config(dir: &Path) -> Config {
4849 storage: Default::default(),
4950 replication: Default::default(),
5051 lfs: Default::default(),
51- ci: Default::default(),
52+ ci: CiConfig {
53+ // Unit tests that claim on an empty queue should not wait out the production long poll.
54+ claim_wait_ms: 50,
55+ ..Default::default()
56+ },
5257 advisories: Default::default(),
5358 mail: Default::default(),
5459 orgs: Default::default(),
crates/forge-web/tests/ci_e2e.rsmodified+13 -6
@@ -11,7 +11,7 @@
1111 //! - a live log: `log.txt` streams while a job runs and ends when the job finishes.
1212
1313 mod common;
14-use common::{BIN, Server, launch, pick_ports, write_config};
14+use common::{BIN, FAST_CLAIMS, Server, launch_with, pick_ports, write_config};
1515 use forge_ci::proto::{JobAssignment, Outcome, RegisterRequest};
1616 use forge_runner::client::ForgeClient;
1717 use forge_runner::config::{Limits, RunnerConfig};
@@ -398,7 +398,7 @@ async fn boot() -> Booted {
398398
399399 run_admin(&config, "tahinli", &["--admin"], TAHINLI_PW);
400400 run_admin(&config, "bob", &[], BOB_PW);
401- let (server, ports) = launch(&dir, ports).await;
401+ let (server, ports) = launch_with(&dir, ports, FAST_CLAIMS).await;
402402 Booted {
403403 _server: server,
404404 _root: root,
@@ -791,18 +791,24 @@ async fn live_log_streams_until_the_job_finishes() {
791791 create_repo(&b.http, &tahinli, "r").await;
792792 let worker = register_runner(&b, &tahinli, "runner-a").await;
793793
794- let slow = r#"[on]
794+ // The job holds until the test drops a release file, so the first line is seen while it runs.
795+ // The loop is capped, so a test that dies early does not leave the job spinning.
796+ let release = b.dir.join("release");
797+ let slow = format!(
798+ r#"[on]
795799 push = ["main"]
796800
797801 [jobs.slow]
798802 image = "docker.io/library/alpine:3"
799-run = "echo started; sleep 5; echo done"
800-"#;
803+run = "echo started; i=0; while [ ! -f {} ] && [ $i -lt 100 ]; do sleep 0.1; i=$((i+1)); done; echo done"
804+"#,
805+ release.display()
806+ );
801807 let work = clone(
802808 &remote(b.port, "tahinli", &token, "tahinli", "r"),
803809 &b.dir.join("tahinli-work"),
804810 );
805- let sha = push_ci_config(&work, slow);
811+ let sha = push_ci_config(&work, &slow);
806812 let found = wait_statuses(&b.http, &token, &sha, &["ci/slow"]).await;
807813 let job_id = job_id_of(&found["ci/slow"]);
808814
@@ -826,6 +832,7 @@ run = "echo started; sleep 5; echo done"
826832 !handle.is_finished(),
827833 "the first line arrived only after the job had finished"
828834 );
835+ fs::write(&release, "").expect("release the job");
829836 }
830837 }
831838 };
crates/forge-web/tests/common/mod.rsmodified+4 -0
@@ -104,6 +104,10 @@ pub fn write_config_with(dir: &Path, ports: Ports, extra: &str) -> PathBuf {
104104 path
105105 }
106106
107+/// `[ci]` settings for tests that drain the queue. A claim that finds nothing waits `claim_wait_ms`
108+/// before it answers 204, and the production default is 25 s, so the test server answers at once.
109+pub const FAST_CLAIMS: &str = "[ci]\nclaim_wait_ms = 50\n";
110+
107111 pub fn describe(out: &Output) -> String {
108112 format!(
109113 "status: {}\nstdout: {}\nstderr: {}",
crates/forge-web/tests/merge_queue_e2e.rsmodified+2 -2
@@ -10,7 +10,7 @@
1010 #![allow(dead_code)]
1111
1212 mod common;
13-use common::{BIN, Server, launch, pick_ports, tool_on_path, write_config};
13+use common::{BIN, FAST_CLAIMS, Server, launch_with, pick_ports, tool_on_path, write_config};
1414 use forge_ci::proto::{JobAssignment, RegisterRequest};
1515 use forge_runner::client::ForgeClient;
1616 use forge_runner::config::{Limits, RunnerConfig};
@@ -339,7 +339,7 @@ async fn boot() -> Booted {
339339
340340 run_admin(&config, "tahinli", &["--admin"], TAHINLI_PW);
341341 run_admin(&config, "bob", &[], BOB_PW);
342- let (server, ports) = launch(&dir, ports).await;
342+ let (server, ports) = launch_with(&dir, ports, FAST_CLAIMS).await;
343343 Booted {
344344 _server: server,
345345 _root: root,