fix(api): reject full action queues
ci / web (pull_request) Successful in 7s
ci / rust (pull_request) Successful in 1m25s
e2e / e2e (pull_request) Successful in 1m27s

This commit is contained in:
Miguel Palhas
2026-08-22 20:33:39 +01:00
parent f40b7588d5
commit b2e4e157c3
2 changed files with 22 additions and 5 deletions
+19 -2
View File
@@ -332,7 +332,6 @@ pub async fn search(
}
state
.send_movie_command(MovieCommand::Search { movie_id: id })
.await
.map_err(|_| ApiError::Unavailable)?;
Ok((StatusCode::ACCEPTED, Json(Accepted { accepted: true })))
}
@@ -383,7 +382,6 @@ pub async fn grab(
movie_id,
release_id,
})
.await
.map_err(|_| ApiError::Unavailable)?;
Ok((StatusCode::ACCEPTED, Json(Accepted { accepted: true })))
}
@@ -537,6 +535,25 @@ mod tests {
);
}
#[tokio::test]
async fn a_full_action_queue_returns_service_unavailable() {
let (_dir, state, base) = application().await;
let movie = add_movie(&base, 693_134, 2).await;
let movie_id = movie["id"].as_i64().expect("id");
for _ in 0..64 {
state
.send_movie_command(MovieCommand::Search { movie_id })
.expect("queue has capacity");
}
let response = reqwest::Client::new()
.post(format!("{base}/api/movies/{movie_id}/search"))
.send()
.await
.expect("search");
assert_eq!(response.status(), StatusCode::SERVICE_UNAVAILABLE);
}
#[tokio::test]
async fn attention_queues_follow_search_and_failure_state() {
let (_dir, state, base) = application().await;
+3 -3
View File
@@ -124,10 +124,10 @@ impl AppState {
self.database.as_ref()
}
pub(crate) async fn send_movie_command(
pub(crate) fn send_movie_command(
&self,
command: MovieCommand,
) -> Result<(), mpsc::error::SendError<MovieCommand>> {
self.movie_commands.send(command).await
) -> Result<(), mpsc::error::TrySendError<MovieCommand>> {
self.movie_commands.try_send(command)
}
}