Exercise PDF cache concurrency and retry test requests
This commit is contained in:
1 parent
f1e0b75499
commit
0a91f7e9db
3 files changed
+54
-16
No files matched your search
+51
-13
@@ -132,21 +132,24 @@ impl TestServer {
|
||||
}
|
||||
|
||||
fn request(&self, method: &str, path: &str, body: &[u8], content_type: &str) -> Response {
|
||||
match send(self.port, method, path, body, content_type) {
|
||||
Ok(response) => response,
|
||||
Err(first) => {
|
||||
std::thread::sleep(Duration::from_millis(200));
|
||||
match send(self.port, method, path, body, content_type) {
|
||||
Ok(response) => response,
|
||||
Err(second) => panic!(
|
||||
"HTTP request failed twice: {first}; {second}
|
||||
server log:
|
||||
{}",
|
||||
self.log()
|
||||
),
|
||||
}
|
||||
let mut errors = Vec::new();
|
||||
for attempt in 0..4 {
|
||||
if attempt > 0 {
|
||||
std::thread::sleep(Duration::from_millis(200 * attempt));
|
||||
}
|
||||
match send(self.port, method, path, body, content_type) {
|
||||
Ok(response) => return response,
|
||||
Err(error) => errors.push(error.to_string()),
|
||||
}
|
||||
}
|
||||
panic!(
|
||||
"HTTP request failed {} times: {}
|
||||
server log:
|
||||
{}",
|
||||
errors.len(),
|
||||
errors.join("; "),
|
||||
self.log()
|
||||
);
|
||||
}
|
||||
|
||||
fn get(&self, path: &str) -> Response {
|
||||
@@ -1884,6 +1887,41 @@ fn concurrent_flat_previews_share_one_cache_entry() {
|
||||
assert_eq!(cached.header("x-texrra-cache"), Some("hit"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn concurrent_flat_pdfs_share_one_cache_entry() {
|
||||
let server = TestServer::start("pdf-cache-concurrency");
|
||||
let source = "Concurrent PDF text.";
|
||||
let mut handles = Vec::new();
|
||||
for _ in 0..3 {
|
||||
let port = server.port;
|
||||
handles.push(std::thread::spawn(move || {
|
||||
let response = send(
|
||||
port,
|
||||
"POST",
|
||||
"/api/route-d/pdf",
|
||||
source.as_bytes(),
|
||||
"text/plain; charset=utf-8",
|
||||
)
|
||||
.expect("concurrent pdf");
|
||||
(response.status, response.body)
|
||||
}));
|
||||
}
|
||||
let mut bodies = std::collections::HashSet::new();
|
||||
for handle in handles {
|
||||
let (status, body) = handle.join().expect("pdf thread");
|
||||
assert_eq!(status, 200);
|
||||
bodies.insert(body);
|
||||
}
|
||||
assert_eq!(bodies.len(), 1, "concurrent PDFs differed");
|
||||
let cached = server.request(
|
||||
"POST",
|
||||
"/api/route-d/pdf",
|
||||
source.as_bytes(),
|
||||
"text/plain; charset=utf-8",
|
||||
);
|
||||
assert_eq!(cached.header("x-texrra-cache"), Some("hit"));
|
||||
}
|
||||
|
||||
fn text_x(svg: &str, needle: &str) -> f64 {
|
||||
let index = svg.find(needle).expect("text run");
|
||||
let prefix = &svg[..index];
|
||||
|
||||
Reference in new issue
Block a user