CI claims wait a configurable time, and the e2e tests set it small
Browse files at this commitf6cbcece6d956ff75b3415bb8a034fba0267a0c2Parent: 9b3e6a7- perf
- CI claims wait a configurable time, and the e2e tests set it small
6 changed files +31 -16
- crates/forge-core/src/config.rs +3 -0
- crates/forge-web/src/ci/api.rs +3 -7
- crates/forge-web/src/test_support.rs +6 -1
- crates/forge-web/tests/ci_e2e.rs +13 -6
- crates/forge-web/tests/common/mod.rs +4 -0
- crates/forge-web/tests/merge_queue_e2e.rs +2 -2
crates/forge-core/src/config.rsmodified+3 -0
| @@ -342,6 +342,8 @@ pub struct CiConfig { | |||
| 342 | pub artifact_retention_days: u64, | 342 | pub artifact_retention_days: u64, |
| 343 | /// Hours a runner registration token stays valid. | 343 | /// Hours a runner registration token stays valid. |
| 344 | pub registration_token_hours: u32, | 344 | 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, | ||
| 345 | } | 347 | } |
| 346 | 348 | ||
| 347 | impl Default for CiConfig { | 349 | impl Default for CiConfig { |
| @@ -354,6 +356,7 @@ impl Default for CiConfig { | |||
| 354 | log_retention_days: 90, | 356 | log_retention_days: 90, |
| 355 | artifact_retention_days: 30, | 357 | artifact_retention_days: 30, |
| 356 | registration_token_hours: 24, | 358 | registration_token_hours: 24, |
| 359 | + claim_wait_ms: 25_000, | ||
| 357 | } | 360 | } |
| 358 | } | 361 | } |
| 359 | } | 362 | } |
crates/forge-web/src/ci/api.rsmodified+3 -7
| @@ -42,11 +42,6 @@ const LOG_SIZE_HEADER: &str = "x-forge-log-size"; | |||
| 42 | const MAX_LOG_CHUNK: usize = 1024 * 1024; | 42 | const MAX_LOG_CHUNK: usize = 1024 * 1024; |
| 43 | /// Largest JSON body on the runner routes, in bytes. | 43 | /// Largest JSON body on the runner routes, in bytes. |
| 44 | const MAX_JSON_BODY: usize = 64 * 1024; | 44 | 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); | ||
| 50 | /// What the forge assumes a runner reserves for a job with no `memory`, when the runner did not say. | 45 | /// What the forge assumes a runner reserves for a job with no `memory`, when the runner did not say. |
| 51 | const DEFAULT_RESERVE: u64 = 1 << 30; | 46 | const DEFAULT_RESERVE: u64 = 1 << 30; |
| 52 | /// Longest runner name or label, in bytes. | 47 | /// Longest runner name or label, in bytes. |
| @@ -343,9 +338,10 @@ async fn claim_work( | |||
| 343 | ) -> topcoat::Result<Response> { | 338 | ) -> topcoat::Result<Response> { |
| 344 | // Arm the wake-up before each attempt, so a job queued during the attempt is not missed. | 339 | // Arm the wake-up before each attempt, so a job queued during the attempt is not missed. |
| 345 | // Producers use notify_waiters, which wakes every claimer, so a runner whose labels | 340 | // 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. |
| 347 | let waker = state.ci_waker.clone(); | 342 | 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; | ||
| 349 | loop { | 345 | loop { |
| 350 | let mut woken = std::pin::pin!(waker.notified()); | 346 | let mut woken = std::pin::pin!(waker.notified()); |
| 351 | woken.as_mut().enable(); | 347 | woken.as_mut().enable(); |
crates/forge-web/src/test_support.rsmodified+6 -1
| @@ -7,6 +7,7 @@ use std::path::Path; | |||
| 7 | use std::sync::Arc; | 7 | use std::sync::Arc; |
| 8 | use std::time::Duration; | 8 | use std::time::Duration; |
| 9 | 9 | ||
| 10 | +use forge_core::config::CiConfig; | ||
| 10 | use forge_core::time::stamp_after; | 11 | use forge_core::time::stamp_after; |
| 11 | use forge_core::token::hash_token; | 12 | use forge_core::token::hash_token; |
| 12 | use forge_core::{Config, Registration, Store}; | 13 | use forge_core::{Config, Registration, Store}; |
| @@ -48,7 +49,11 @@ pub fn test_config(dir: &Path) -> Config { | |||
| 48 | storage: Default::default(), | 49 | storage: Default::default(), |
| 49 | replication: Default::default(), | 50 | replication: Default::default(), |
| 50 | lfs: Default::default(), | 51 | 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 | + }, | ||
| 52 | advisories: Default::default(), | 57 | advisories: Default::default(), |
| 53 | mail: Default::default(), | 58 | mail: Default::default(), |
| 54 | orgs: Default::default(), | 59 | orgs: Default::default(), |
crates/forge-web/tests/ci_e2e.rsmodified+13 -6
| @@ -11,7 +11,7 @@ | |||
| 11 | //! - a live log: `log.txt` streams while a job runs and ends when the job finishes. | 11 | //! - a live log: `log.txt` streams while a job runs and ends when the job finishes. |
| 12 | 12 | ||
| 13 | mod common; | 13 | 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}; |
| 15 | use forge_ci::proto::{JobAssignment, Outcome, RegisterRequest}; | 15 | use forge_ci::proto::{JobAssignment, Outcome, RegisterRequest}; |
| 16 | use forge_runner::client::ForgeClient; | 16 | use forge_runner::client::ForgeClient; |
| 17 | use forge_runner::config::{Limits, RunnerConfig}; | 17 | use forge_runner::config::{Limits, RunnerConfig}; |
| @@ -398,7 +398,7 @@ async fn boot() -> Booted { | |||
| 398 | 398 | ||
| 399 | run_admin(&config, "tahinli", &["--admin"], TAHINLI_PW); | 399 | run_admin(&config, "tahinli", &["--admin"], TAHINLI_PW); |
| 400 | run_admin(&config, "bob", &[], BOB_PW); | 400 | 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; |
| 402 | Booted { | 402 | Booted { |
| 403 | _server: server, | 403 | _server: server, |
| 404 | _root: root, | 404 | _root: root, |
| @@ -791,18 +791,24 @@ async fn live_log_streams_until_the_job_finishes() { | |||
| 791 | create_repo(&b.http, &tahinli, "r").await; | 791 | create_repo(&b.http, &tahinli, "r").await; |
| 792 | let worker = register_runner(&b, &tahinli, "runner-a").await; | 792 | let worker = register_runner(&b, &tahinli, "runner-a").await; |
| 793 | 793 | ||
| 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] | ||
| 795 | push = ["main"] | 799 | push = ["main"] |
| 796 | 800 | ||
| 797 | [jobs.slow] | 801 | [jobs.slow] |
| 798 | image = "docker.io/library/alpine:3" | 802 | image = "docker.io/library/alpine:3" |
| 799 | -run = "echo started; sleep 5; echo done" | 803 | +run = "echo started; i=0; while [ ! -f {} ] && [ $i -lt 100 ]; do sleep 0.1; i=$((i+1)); done; echo done" |
| 800 | -"#; | 804 | +"#, |
| 805 | + release.display() | ||
| 806 | + ); | ||
| 801 | let work = clone( | 807 | let work = clone( |
| 802 | &remote(b.port, "tahinli", &token, "tahinli", "r"), | 808 | &remote(b.port, "tahinli", &token, "tahinli", "r"), |
| 803 | &b.dir.join("tahinli-work"), | 809 | &b.dir.join("tahinli-work"), |
| 804 | ); | 810 | ); |
| 805 | - let sha = push_ci_config(&work, slow); | 811 | + let sha = push_ci_config(&work, &slow); |
| 806 | let found = wait_statuses(&b.http, &token, &sha, &["ci/slow"]).await; | 812 | let found = wait_statuses(&b.http, &token, &sha, &["ci/slow"]).await; |
| 807 | let job_id = job_id_of(&found["ci/slow"]); | 813 | let job_id = job_id_of(&found["ci/slow"]); |
| 808 | 814 | ||
| @@ -826,6 +832,7 @@ run = "echo started; sleep 5; echo done" | |||
| 826 | !handle.is_finished(), | 832 | !handle.is_finished(), |
| 827 | "the first line arrived only after the job had finished" | 833 | "the first line arrived only after the job had finished" |
| 828 | ); | 834 | ); |
| 835 | + fs::write(&release, "").expect("release the job"); | ||
| 829 | } | 836 | } |
| 830 | } | 837 | } |
| 831 | }; | 838 | }; |
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 { | |||
| 104 | path | 104 | path |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 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 | + | ||
| 107 | pub fn describe(out: &Output) -> String { | 111 | pub fn describe(out: &Output) -> String { |
| 108 | format!( | 112 | format!( |
| 109 | "status: {}\nstdout: {}\nstderr: {}", | 113 | "status: {}\nstdout: {}\nstderr: {}", |
crates/forge-web/tests/merge_queue_e2e.rsmodified+2 -2
| @@ -10,7 +10,7 @@ | |||
| 10 | #![allow(dead_code)] | 10 | #![allow(dead_code)] |
| 11 | 11 | ||
| 12 | mod common; | 12 | 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}; |
| 14 | use forge_ci::proto::{JobAssignment, RegisterRequest}; | 14 | use forge_ci::proto::{JobAssignment, RegisterRequest}; |
| 15 | use forge_runner::client::ForgeClient; | 15 | use forge_runner::client::ForgeClient; |
| 16 | use forge_runner::config::{Limits, RunnerConfig}; | 16 | use forge_runner::config::{Limits, RunnerConfig}; |
| @@ -339,7 +339,7 @@ async fn boot() -> Booted { | |||
| 339 | 339 | ||
| 340 | run_admin(&config, "tahinli", &["--admin"], TAHINLI_PW); | 340 | run_admin(&config, "tahinli", &["--admin"], TAHINLI_PW); |
| 341 | run_admin(&config, "bob", &[], BOB_PW); | 341 | 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; |
| 343 | Booted { | 343 | Booted { |
| 344 | _server: server, | 344 | _server: server, |
| 345 | _root: root, | 345 | _root: root, |