fix: reduce TUI idle CPU and improve server error banners
- Replace non-blocking try_recv() event loop with blocking recv() to eliminate idle spin; the sender tick timeout still drives minimum wakeup rate so the UI stays responsive - Lower default tick rate from 50 ms to 100 ms (10 ticks/sec vs 20); add MANAGARR_TICK_RATE_MS env var for runtime tuning - Move terminal draws to event boundaries (key + tick) instead of every loop pass, reducing unnecessary redraws - In network error handling, prefer concise JSON fields (message / errorMessage / error) over the raw HTTP body, so Radarr ASP.NET stack traces don't flood the TUI banner; full body still logged - Add unit tests for tick-rate parsing and Radarr-style JSON error body Observed: ~0.6% total CPU at idle vs measurably higher with prod defaults
This commit is contained in:
1 parent
6e7707f6df
commit
6c41e0704e
4 files changed
+114
-10
No files matched your search
@@ -353,6 +353,48 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_request_non_success_code_uses_json_message_for_error_body() {
|
||||
let mut server = Server::new_async().await;
|
||||
let async_server = server
|
||||
.mock("GET", "/test")
|
||||
.match_header("X-Api-Key", "test1234")
|
||||
.with_status(500)
|
||||
.with_body(json!({
|
||||
"message": "database is locked\ndatabase is locked",
|
||||
"description": "at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker"
|
||||
}).to_string())
|
||||
.create_async()
|
||||
.await;
|
||||
let app_arc = Arc::new(Mutex::new(App::test_default()));
|
||||
let mut network = test_network(&app_arc);
|
||||
|
||||
let resp = network
|
||||
.handle_request::<(), Test>(
|
||||
RequestProps {
|
||||
uri: format!("{}/test", server.url()),
|
||||
method: RequestMethod::Get,
|
||||
body: None,
|
||||
api_token: "test1234".to_owned(),
|
||||
ignore_status_code: false,
|
||||
custom_headers: HeaderMap::new(),
|
||||
},
|
||||
|response, mut app| app.error = HorizontallyScrollableText::from(response.value),
|
||||
)
|
||||
.await;
|
||||
|
||||
async_server.assert_async().await;
|
||||
assert_str_eq!(
|
||||
app_arc.lock().await.error.text,
|
||||
"Request failed. Received 500 Internal Server Error response code with body: database is locked database is locked"
|
||||
);
|
||||
assert!(resp.is_err());
|
||||
assert_str_eq!(
|
||||
resp.unwrap_err().to_string(),
|
||||
"Request failed. Received 500 Internal Server Error response code with body: database is locked database is locked"
|
||||
);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[tokio::test]
|
||||
async fn test_call_api(
|
||||
|
||||
Reference in new issue
Block a user