mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-24 10:08:00 -06:00
Control channel tests: a 5 s linger for the two linger tests
Their timing checks (the auth round trips finishing within the linger, and a non-lingering connection failing a write within half of it) had only 1 s and 500 ms of margin with TEST_LIMITS. Each now serves with its own Limits and a 5 s linger; the assertions are unchanged and neither test waits for the linger on its passing path.
This commit is contained in:
@@ -1233,8 +1233,10 @@ mod transport_tests {
|
||||
#[test]
|
||||
fn a_lingering_connection_holds_no_place_to_authenticate() {
|
||||
use std::io::{BufReader, Write};
|
||||
// A linger far longer than the checks below take, even on a loaded machine.
|
||||
let limits = super::Limits { linger: std::time::Duration::from_secs(5), ..TEST_LIMITS };
|
||||
let (_control, client) = super::attach(&egui::Context::default());
|
||||
let ep = super::serve_with(client, TEST_LIMITS).unwrap();
|
||||
let ep = super::serve_with(client, limits).unwrap();
|
||||
let auth = serde_json::json!({ "jsonrpc": "2.0", "id": 1, "method": "auth", "params": { "token": ep.token } });
|
||||
// Refused with most of its line unread, and left open: it lingers for `linger`.
|
||||
let refused = connect(ep.port);
|
||||
@@ -1243,14 +1245,14 @@ mod transport_tests {
|
||||
assert_eq!(next_line(&mut r).expect("refused with a reason")["error"]["code"], -32600);
|
||||
// Well within the linger, both places are free for new connections.
|
||||
let started = std::time::Instant::now();
|
||||
let others: Vec<_> = (0..TEST_LIMITS.max_unauthenticated).map(|_| connect(ep.port)).collect();
|
||||
let others: Vec<_> = (0..limits.max_unauthenticated).map(|_| connect(ep.port)).collect();
|
||||
for s in &others {
|
||||
// A refused one has already been closed, so its write may fail; its reply says why.
|
||||
let _ = writeln!(s.try_clone().unwrap(), "{auth}");
|
||||
let reply = next_line(&mut BufReader::new(s.try_clone().unwrap())).expect("a reply");
|
||||
assert_eq!(reply["result"]["ok"], true, "admitted while the refused one lingers: {reply}");
|
||||
}
|
||||
assert!(started.elapsed() < TEST_LIMITS.linger, "checked while it lingered: {:?}", started.elapsed());
|
||||
assert!(started.elapsed() < limits.linger, "checked while it lingered: {:?}", started.elapsed());
|
||||
drop(refused);
|
||||
}
|
||||
|
||||
@@ -1260,7 +1262,8 @@ mod transport_tests {
|
||||
#[test]
|
||||
fn only_so_many_refused_connections_linger() {
|
||||
use std::io::{BufReader, Write};
|
||||
let limits = super::Limits { max_lingering: 1, ..TEST_LIMITS };
|
||||
// A linger far longer than the checks below take, even on a loaded machine.
|
||||
let limits = super::Limits { linger: std::time::Duration::from_secs(5), max_lingering: 1, ..TEST_LIMITS };
|
||||
let (_control, client) = super::attach(&egui::Context::default());
|
||||
let ep = super::serve_with(client, limits).unwrap();
|
||||
let bad = r#"{"jsonrpc": "2.0", "id": 1, "method": "page_count"}"#;
|
||||
|
||||
Reference in New Issue
Block a user