git-ents.gitmain
⌘K
foforge
commit 8eb6832
refactor: remove --max-requests and graceful-shutdown plumbing

The flag existed only for one test, which now kills the child like the other server tests. Drops the counter middleware, the Notify, and with_graceful_shutdown.

removes: --max-requests flag Assisted-by: Claude:claude-opus-4-8

Joseph D. Carpinelli · 1 month ago

Reviews

No reviews of this commit yet — record a verdict below.

Start a review

verdict

crates/git-ents-server/src/main.rs @@ -10,13 +10,12 @@ use std::path::PathBuf; use std::process::ExitCode; use std::sync::Arc; -use std::sync::atomic::{AtomicUsize, Ordering}; use axum::Router; use axum::extract::DefaultBodyLimit; use axum::routing::get; use clap::{CommandFactory, Parser, Subcommand}; -use tokio::sync::{Mutex, Notify}; +use tokio::sync::Mutex; #[derive(Parser)] #[command( @@ -56,10 +55,6 @@ default_value = "/data/checks-queue" )] checks_queue: PathBuf, - - /// Stop after handling this many requests. - #[arg(long)] - max_requests: Option<usize>, } /// Subcommands that run instead of serving HTTP. @@ -146,34 +141,12 @@ // The git smart-HTTP protocol streams whole packfiles through the request // body, so the default 2 MiB cap would reject any non-trivial push. - let mut app = Router::new() + let app = Router::new() .route("/healthz", get(http::health)) .fallback(http::git) .layer(DefaultBodyLimit::disable()) .with_state(state); - // When `--max-requests` is set, count every response and signal shutdown - // once the limit is reached so the process exits on its own. - let shutdown = Arc::new(Notify::new()); - if let Some(max) = args.max_requests { - let counter = Arc::new(AtomicUsize::new(0)); - let notify = shutdown.clone(); - app = app.layer(axum::middleware::from_fn( - move |req: axum::extract::Request, next: axum::middleware::Next| { - let counter = counter.clone(); - let notify = notify.clone(); - async move { - let response = next.run(req).await; - let handled = counter.fetch_add(1, Ordering::SeqCst).saturating_add(1); - if handled >= max { - notify.notify_one(); - } - response - } - }, - )); - } - let addr = SocketAddr::from(([0, 0, 0, 0], args.port)); let listener = match tokio::net::TcpListener::bind(addr).await { Ok(listener) => listener, @@ -183,9 +156,7 @@ } }; - let server = - axum::serve(listener, app).with_graceful_shutdown(async move { shutdown.notified().await }); - if let Err(e) = server.await { + if let Err(e) = axum::serve(listener, app).await { eprintln!("error: {e}"); return ExitCode::FAILURE; }
crates/git-ents-server/tests/server.rs @@ -14,30 +14,20 @@ use rstest::rstest; #[test] -fn responds_and_shuts_down() { - let probe = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); - let port = probe.local_addr().unwrap().port(); - drop(probe); +fn responds_to_requests() { + let port = free_port(); let mut child = Command::new(env!("CARGO_BIN_EXE_git-ents-server")) .arg("--port") .arg(port.to_string()) - .arg("--max-requests") - .arg("3") .spawn() .unwrap(); + wait_for_port(port); + for i in 0..3 { - let deadline = std::time::Instant::now() + std::time::Duration::from_secs(5); - let mut stream = loop { - match TcpStream::connect(format!("127.0.0.1:{port}")) { - Ok(s) => break s, - Err(_) if std::time::Instant::now() < deadline => { - std::thread::sleep(std::time::Duration::from_millis(10)); - } - Err(e) => panic!("could not connect on request {i}: {e}"), - } - }; + let mut stream = TcpStream::connect(format!("127.0.0.1:{port}")) + .unwrap_or_else(|e| panic!("could not connect on request {i}: {e}")); stream.write_all(b"GET / HTTP/1.0\r\n\r\n").unwrap(); let mut response = String::new(); stream.read_to_string(&mut response).unwrap(); @@ -47,8 +37,8 @@ ); } - let status = child.wait().unwrap(); - assert!(status.success()); + child.kill().unwrap(); + let _wait = child.wait(); } #[test]