forge
Explore
Log in

Don't you dare go Hollow

Stop the slow e2e tests waiting on delays they do not check

Browse files at this commit

5f0038cd6dc7f5dfc4da76725ac65f92bfc8f973Ahmet Kaan GümüşParent: cbc0d0b
  • perf
    • stop the slow e2e tests waiting on delays they do not check
Show full message
⚡ perf: stop the slow e2e tests waiting on delays they do not check

Where the time went (isolated runs, before -> after):

- ssh_e2e clone_push_clone_over_ssh: 16.9 s -> 0.5 s
  Every SSH connection's first `none` auth probe was rejected, and russh
  answered each rejection after a fixed 1 s delay. The delay is now the
  `ssh_auth_rejection_secs` setting (default 1, production unchanged); the
  e2e harness and the SSH test set 0.

- mirrors_e2e pull_and_push_mirrors_sync_over_smart_http: 12.9 s -> 3.5 s
  A push mirror waited the hard-coded 10 s push debounce. The debounce is now
  `[mirrors] push_debounce_secs` (default 10, production unchanged); the test
  sets 0.

- git_e2e git_end_to_end: 9.5 s -> 2.9 s
  Its SSH operations paid the same 1 s auth delay as above.

- ci::api::tests::runner_binary_streams_the_running_binary_with_its_sha:
  32 s -> 9.2 s (shared run). The binary body was streamed in 4 KiB frames
  (ReaderStream default), about 350k frames for a 1.4 GB debug binary. Now
  64 KiB frames. The served bytes and assertions are unchanged.

Also: debug builds now optimize argon2, blake2, ml-kem, keccak,
curve25519-dalek, ed25519-dalek and chacha20 (same pattern as sha2), so
password hashing and SSH crypto are fast in tests. Release is unaffected.
Cargo.tomlmodified+18 -1
@@ -127,11 +127,28 @@ opt-level = 3
127 opt-level = 3127 opt-level = 3
128 [profile.dev.package.turso_parser]128 [profile.dev.package.turso_parser]
129 opt-level = 3129 opt-level = 3
130+# Password hashing (argon2id, default cost) and the SSH key exchange and ciphers run in every e2e
131+# test's login and connection. Unoptimized they take hundreds of ms each. Release is unaffected.
130 [profile.dev.package.argon2]132 [profile.dev.package.argon2]
131-# password hashing runs unoptimized in tests and dominates the login tests.
132 opt-level = 3133 opt-level = 3
133 [profile.dev.package.blake2]134 [profile.dev.package.blake2]
134 opt-level = 3135 opt-level = 3
136+[profile.dev.package.ml-kem]
137+opt-level = 3
138+[profile.dev.package.module-lattice]
139+opt-level = 3
140+[profile.dev.package.keccak]
141+opt-level = 3
142+[profile.dev.package.curve25519-dalek]
143+opt-level = 3
144+[profile.dev.package.ed25519-dalek]
145+opt-level = 3
146+[profile.dev.package.chacha20poly1305]
147+opt-level = 3
148+[profile.dev.package.chacha20]
149+opt-level = 3
150+[profile.dev.package.poly1305]
151+opt-level = 3
135 152
136 [profile.release]153 [profile.release]
137 lto = true154 lto = true
config/forge.example.tomlmodified+7 -0
@@ -33,6 +33,13 @@ trusted_proxies = []
33 # Exact hostnames or CIDR networks that may be reached even if they resolve to internal addresses.33 # Exact hostnames or CIDR networks that may be reached even if they resolve to internal addresses.
34 # allowed_hosts = ["hooks.internal.example", "10.20.0.0/16"]34 # allowed_hosts = ["hooks.internal.example", "10.20.0.0/16"]
35 35
36+# Mirror sync timing. A push mirror runs this many seconds after the last ref update.
37+# [mirrors]
38+# push_debounce_secs = 10
39+
40+# Seconds a failed SSH login waits before it is refused (brute-force damping). Default 1.
41+# ssh_auth_rejection_secs = 1
42+
36 # Scheduled backups (see docs/backup.md). Empty dir disables the scheduler.43 # Scheduled backups (see docs/backup.md). Empty dir disables the scheduler.
37 # [backup]44 # [backup]
38 # Directory that receives the backup sets. Ship it off-site with restic or rclone.45 # Directory that receives the backup sets. Ship it off-site with restic or rclone.
crates/forge-core/src/config.rsmodified+27 -0
@@ -35,6 +35,10 @@ fn deserialize_trusted_proxies<'de, D: Deserializer<'de>>(
35 .collect()35 .collect()
36 }36 }
37 37
38+fn default_ssh_auth_rejection_secs() -> u64 {
39+ 1
40+}
41+
38 fn default_user_content_listen() -> SocketAddr {42 fn default_user_content_listen() -> SocketAddr {
39 "127.0.0.1:7661"43 "127.0.0.1:7661"
40 .parse()44 .parse()
@@ -67,6 +71,10 @@ pub struct Config {
67 pub ssh_listen: SocketAddr,71 pub ssh_listen: SocketAddr,
68 pub ssh_public_host: String,72 pub ssh_public_host: String,
69 pub ssh_public_port: u16,73 pub ssh_public_port: u16,
74+ /// Seconds a failed SSH authentication waits before it is answered (brute-force damping).
75+ /// Every SSH connection's first `none` probe fails, so this is paid per connection.
76+ #[serde(default = "default_ssh_auth_rejection_secs")]
77+ pub ssh_auth_rejection_secs: u64,
70 pub registration: Registration,78 pub registration: Registration,
71 /// Peers whose `X-Forwarded-For` header is trusted, such as the reverse proxy in front of forge.79 /// Peers whose `X-Forwarded-For` header is trusted, such as the reverse proxy in front of forge.
72 /// Entries are addresses or CIDR networks. Empty by default, so the TCP peer is the client.80 /// Entries are addresses or CIDR networks. Empty by default, so the TCP peer is the client.
@@ -111,6 +119,25 @@ pub struct Config {
111 /// Alerts to site admins, from the `[alerts]` section.119 /// Alerts to site admins, from the `[alerts]` section.
112 #[serde(default)]120 #[serde(default)]
113 pub alerts: AlertsConfig,121 pub alerts: AlertsConfig,
122+ /// Mirror sync timing, from the `[mirrors]` section.
123+ #[serde(default)]
124+ pub mirrors: MirrorsConfig,
125+}
126+
127+/// Mirror sync timing. The default is what production runs with; the e2e tests shorten it.
128+#[derive(Debug, Clone, Deserialize)]
129+#[serde(deny_unknown_fields, default)]
130+pub struct MirrorsConfig {
131+ /// Seconds a push mirror waits after the last ref update before it is sent.
132+ pub push_debounce_secs: u64,
133+}
134+
135+impl Default for MirrorsConfig {
136+ fn default() -> Self {
137+ MirrorsConfig {
138+ push_debounce_secs: 10,
139+ }
140+ }
114 }141 }
115 142
116 /// Admin alerts: what the forge tells the site admins about before something breaks.143 /// Admin alerts: what the forge tells the site admins about before something breaks.
crates/forge-ssh/src/server.rsmodified+3 -3
@@ -33,8 +33,6 @@ const PUMP_CHUNK: usize = 32 * 1024;
33 /// Client input chunks buffered in front of the child's stdin. This bounds memory and33 /// Client input chunks buffered in front of the child's stdin. This bounds memory and
34 /// propagates backpressure to the SSH read loop.34 /// propagates backpressure to the SSH read loop.
35 const STDIN_QUEUE: usize = 32;35 const STDIN_QUEUE: usize = 32;
36-/// Constant delay applied to failed authentication attempts.
37-const AUTH_REJECTION_TIME: Duration = Duration::from_secs(1);
38 /// Failed publickey attempts before the connection is dropped.36 /// Failed publickey attempts before the connection is dropped.
39 const MAX_AUTH_ATTEMPTS: usize = 6;37 const MAX_AUTH_ATTEMPTS: usize = 6;
40 38
@@ -44,6 +42,8 @@ pub struct SshConfig {
44 pub host_key_path: PathBuf,42 pub host_key_path: PathBuf,
45 pub auth_timeout: Duration,43 pub auth_timeout: Duration,
46 pub inactivity_timeout: Duration,44 pub inactivity_timeout: Duration,
45+ /// Delay before a failed authentication attempt is answered (forge-web: `ssh_auth_rejection_secs`).
46+ pub auth_rejection_time: Duration,
47 }47 }
48 48
49 /// Runs the SSH server until it fails. Creates the ed25519 host key on first boot.49 /// Runs the SSH server until it fails. Creates the ed25519 host key on first boot.
@@ -52,7 +52,7 @@ pub async fn run<B: GitBackend>(config: SshConfig, backend: Arc<B>) -> Result<()
52 let russh_config = Arc::new(Config {52 let russh_config = Arc::new(Config {
53 keys: vec![host_key],53 keys: vec![host_key],
54 methods: publickey_only(),54 methods: publickey_only(),
55- auth_rejection_time: AUTH_REJECTION_TIME,55+ auth_rejection_time: config.auth_rejection_time,
56 max_auth_attempts: MAX_AUTH_ATTEMPTS,56 max_auth_attempts: MAX_AUTH_ATTEMPTS,
57 inactivity_timeout: Some(config.inactivity_timeout),57 inactivity_timeout: Some(config.inactivity_timeout),
58 preferred: preferred_algorithms(),58 preferred: preferred_algorithms(),
crates/forge-ssh/tests/ssh_e2e.rsmodified+3 -0
@@ -193,6 +193,9 @@ async fn clone_push_clone_over_ssh() {
193 host_key_path: host_key.clone(),193 host_key_path: host_key.clone(),
194 auth_timeout: Duration::from_secs(10),194 auth_timeout: Duration::from_secs(10),
195 inactivity_timeout: Duration::from_secs(60),195 inactivity_timeout: Duration::from_secs(60),
196+ // Production rejects a failed auth after 1s. OpenSSH's `none` probe fails on every
197+ // connection, so the test would wait that second for each of its ~20 connections.
198+ auth_rejection_time: Duration::ZERO,
196 };199 };
197 tokio::spawn(forge_ssh::run(config, std::sync::Arc::new(backend)));200 tokio::spawn(forge_ssh::run(config, std::sync::Arc::new(backend)));
198 wait_for_port(port).await;201 wait_for_port(port).await;
crates/forge-web/src/boot.rsmodified+2 -0
@@ -41,6 +41,7 @@ pub async fn serve(
41 let listen = config.listen;41 let listen = config.listen;
42 let user_content_listen = config.user_content_listen;42 let user_content_listen = config.user_content_listen;
43 let ssh_listen = config.ssh_listen;43 let ssh_listen = config.ssh_listen;
44+ let ssh_auth_rejection_time = Duration::from_secs(config.ssh_auth_rejection_secs);
44 45
45 std::fs::create_dir_all(&config.data_dir)?;46 std::fs::create_dir_all(&config.data_dir)?;
46 // The data dir holds the instance key and the internal socket. Keep it private to this user.47 // The data dir holds the instance key and the internal socket. Keep it private to this user.
@@ -211,6 +212,7 @@ pub async fn serve(
211 host_key_path: data_dir.join("ssh_host_ed25519_key"),212 host_key_path: data_dir.join("ssh_host_ed25519_key"),
212 auth_timeout: Duration::from_secs(30),213 auth_timeout: Duration::from_secs(30),
213 inactivity_timeout: Duration::from_secs(10 * 60),214 inactivity_timeout: Duration::from_secs(10 * 60),
215+ auth_rejection_time: ssh_auth_rejection_time,
214 };216 };
215 let ssh_backend = Arc::new(SshBackend {217 let ssh_backend = Arc::new(SshBackend {
216 state: state.clone(),218 state: state.clone(),
crates/forge-web/src/mirrors/mod.rsmodified+3 -5
@@ -27,8 +27,6 @@ use crate::post_update::after_ref_update;
27 use crate::state::AppState;27 use crate::state::AppState;
28 use crate::webhooks::client::{WebhookPolicy, is_forbidden_ip, validate_url};28 use crate::webhooks::client::{WebhookPolicy, is_forbidden_ip, validate_url};
29 29
30-/// How long a push waits after the last ref update before it is sent.
31-pub const PUSH_DEBOUNCE: Duration = Duration::from_secs(10);
32 /// Hard limit on one sync run. The git process is killed when it passes.30 /// Hard limit on one sync run. The git process is killed when it passes.
33 pub const RUN_TIMEOUT: Duration = Duration::from_secs(10 * 60);31 pub const RUN_TIMEOUT: Duration = Duration::from_secs(10 * 60);
34 /// The all-zero object id git uses for a ref that does not exist on one side.32 /// The all-zero object id git uses for a ref that does not exist on one side.
@@ -36,10 +34,10 @@ pub const ZERO_OID: &str = "0000000000000000000000000000000000000000";
36 /// Next run for a mirror whose interval is `0` (manual only).34 /// Next run for a mirror whose interval is `0` (manual only).
37 const FAR_FUTURE: &str = "9999-12-31T23:59:59.999999999Z";35 const FAR_FUTURE: &str = "9999-12-31T23:59:59.999999999Z";
38 36
39-/// Queues every enabled push mirror of a repo for a sync `PUSH_DEBOUNCE` from now, and wakes the37+/// Queues every enabled push mirror of a repo for a sync after the `[mirrors]` push debounce, and
40-/// worker. Called after a branch or tag update.38+/// wakes the worker. Called after a branch or tag update.
41 pub async fn enqueue_push_mirrors(state: &AppState, repo_id: &str) -> forge_core::Result<()> {39 pub async fn enqueue_push_mirrors(state: &AppState, repo_id: &str) -> forge_core::Result<()> {
42- let due = stamp_after(PUSH_DEBOUNCE);40+ let due = stamp_after(Duration::from_secs(state.config.mirrors.push_debounce_secs));
43 let mut queued = false;41 let mut queued = false;
44 for mirror in state.store.list_mirrors(repo_id).await? {42 for mirror in state.store.list_mirrors(repo_id).await? {
45 if mirror.direction == MirrorDirection::Push && mirror.enabled {43 if mirror.direction == MirrorDirection::Push && mirror.enabled {
crates/forge-web/src/pages/settings_security.rsmodified+2 -0
@@ -1076,6 +1076,8 @@ mod tests {
1076 self_update: Default::default(),1076 self_update: Default::default(),
1077 banner: Default::default(),1077 banner: Default::default(),
1078 alerts: Default::default(),1078 alerts: Default::default(),
1079+ mirrors: Default::default(),
1080+ ssh_auth_rejection_secs: 1,
1079 };1081 };
1080 let config = Arc::new(config);1082 let config = Arc::new(config);
1081 let state = AppState {1083 let state = AppState {
crates/forge-web/src/self_update.rsmodified+4 -1
@@ -370,7 +370,10 @@ pub async fn binary_response() -> Result<Response, String> {
370 .await370 .await
371 .map_err(|e| e.to_string())?;371 .map_err(|e| e.to_string())?;
372 let len = file.metadata().await.map_err(|e| e.to_string())?.len();372 let len = file.metadata().await.map_err(|e| e.to_string())?.len();
373- let frames = ReaderStream::new(file).map(|chunk| chunk.map(http_body::Frame::data));373+ // 64 KiB frames, not ReaderStream's 4 KiB default: the binary is ~1 GB, and 4 KiB frames mean
374+ // ~250k body frames to push through hyper for every download.
375+ let frames =
376+ ReaderStream::with_capacity(file, 64 * 1024).map(|chunk| chunk.map(http_body::Frame::data));
374 let mut res = Response::new(Body::new(StreamBody::new(frames)));377 let mut res = Response::new(Body::new(StreamBody::new(frames)));
375 let headers = res.headers_mut();378 let headers = res.headers_mut();
376 headers.insert(379 headers.insert(
crates/forge-web/src/test_support.rsmodified+2 -0
@@ -60,6 +60,8 @@ pub fn test_config(dir: &Path) -> Config {
60 self_update: Default::default(),60 self_update: Default::default(),
61 banner: Default::default(),61 banner: Default::default(),
62 alerts: Default::default(),62 alerts: Default::default(),
63+ mirrors: Default::default(),
64+ ssh_auth_rejection_secs: 1,
63 }65 }
64 }66 }
65 67
crates/forge-web/tests/common/mod.rsmodified+2 -1
@@ -97,7 +97,8 @@ pub fn write_config_with(dir: &Path, ports: Ports, extra: &str) -> PathBuf {
97 ssh_listen = \"127.0.0.1:{ssh_port}\"\n\97 ssh_listen = \"127.0.0.1:{ssh_port}\"\n\
98 ssh_public_host = \"127.0.0.1\"\n\98 ssh_public_host = \"127.0.0.1\"\n\
99 ssh_public_port = {ssh_port}\n\99 ssh_public_port = {ssh_port}\n\
100- registration = \"closed\"\n{extra}"100+ registration = \"closed\"\n\
101+ ssh_auth_rejection_secs = 0\n{extra}"
101 );102 );
102 let path = dir.join("forge.toml");103 let path = dir.join("forge.toml");
103 fs::write(&path, text).expect("write config");104 fs::write(&path, text).expect("write config");
crates/forge-web/tests/mirrors_e2e.rsmodified+3 -3
@@ -20,10 +20,10 @@ use std::time::{Duration, Instant};
20 use reqwest::header::{LOCATION, SET_COOKIE};20 use reqwest::header::{LOCATION, SET_COOKIE};
21 21
22 const TAHINLI_PW: &str = "tahinli-password-123";22 const TAHINLI_PW: &str = "tahinli-password-123";
23-const WEBHOOK_TOML: &str = "\n[webhooks]\nallow_http = true\nallowed_hosts = [\"127.0.0.1\"]\n";23+const WEBHOOK_TOML: &str = "\n[webhooks]\nallow_http = true\nallowed_hosts = [\"127.0.0.1\"]\n\n[mirrors]\npush_debounce_secs = 0\n";
24 const SYNC_TIMEOUT: Duration = Duration::from_secs(30);24 const SYNC_TIMEOUT: Duration = Duration::from_secs(30);
25-/// Push mirrors run after the 10s debounce, but the worker only re-checks on its 60s poll (or a25+/// Push mirrors run after the push debounce, which this test sets to 0 (production: 10s). The
26-/// wake-up, which fires before the debounce expires). Allow poll plus debounce plus slack.26+/// worker wakes on the push itself, so this only needs room for the git sync.
27 const PUSH_TIMEOUT: Duration = Duration::from_secs(90);27 const PUSH_TIMEOUT: Duration = Duration::from_secs(90);
28 28
29 struct Resp {29 struct Resp {