Exercise PDF cache concurrency and retry test requests
This commit is contained in:
1 parent
f1e0b75499
commit
0a91f7e9db
3 files changed
+52
-14
No files matched your search
@@ -48,7 +48,7 @@ floats (`\floatsep`, `\textfloatsep`, `\intextsep`, `\topfraction`,
|
|||||||
`\bottomnumber`, `\totalnumber`), insertion classes (`\skip`, fraction and
|
`\bottomnumber`, `\totalnumber`), insertion classes (`\skip`, fraction and
|
||||||
absolute limits, splitting), marks, Rust output hook, multi-page PDF, and the
|
absolute limits, splitting), marks, Rust output hook, multi-page PDF, and the
|
||||||
route-D service endpoints (`/api/route-d/preview|pdf|edit`, project preview and
|
route-D service endpoints (`/api/route-d/preview|pdf|edit`, project preview and
|
||||||
PDF opt-in with `?engine=route-d`). 777 workspace tests are green and no oracle
|
PDF opt-in with `?engine=route-d`). 778 workspace tests are green and no oracle
|
||||||
fixture is ignored.
|
fixture is ignored.
|
||||||
|
|
||||||
Status after G1 (P0-P2): the paragraph model reproduces TeX's passes,
|
Status after G1 (P0-P2): the paragraph model reproduces TeX's passes,
|
||||||
|
|||||||
+2
-2
@@ -333,7 +333,7 @@ for a later overlaid slash.
|
|||||||
| M4 math | partial | atoms, scripts, fractions (including infix `\over`/`\atop`/`\choose`), roots, delimiters, accents, operators, classes, braces, boxed, negated, math alphabets (incl. `\mathcal`, `\mathbb` and `\mathfrak`), `align`/`gather` rows with per-row tags; no math painter/shrink wrapping |
|
| M4 math | partial | atoms, scripts, fractions (including infix `\over`/`\atop`/`\choose`), roots, delimiters, accents, operators, classes, braces, boxed, negated, math alphabets (incl. `\mathcal`, `\mathbb` and `\mathfrak`), `align`/`gather` rows with per-row tags; no math painter/shrink wrapping |
|
||||||
| M5 NFSS/TFM | partial | runtime `cmr10.tfm` widths/heights/depths/kern pairs and ff/fi/fl/ffi/ffl ligatures; text faces embed Liberation Serif/Mono as Type0 CID fonts with Identity-H, ToUnicode and width arrays; used faces embed per-document TrueType glyf subsets that keep the original glyph IDs, include composite components, and carry a matching ToUnicode CMap; ASCII documents use the compact tier; no Base-14 dependency; SVG carries family/weight/style; route-D PDFs embed Knuth's Computer Modern Type1 programs (cmr10/cmbx10/cmti10/cmbxti10/cmtt10/cmss10/cmssbx10/cmssi10/cmcsc10/cmsl10/cmbxsl10/cmitt10) as `/Subtype /Type1` fonts with `/FontFile` (`Length1/2/3`), `/Encoding /Differences` and TFM `/Widths`, falling back per glyph to a Liberation subset when a character is outside the encoding while the rest of the face stays in Computer Modern |
|
| M5 NFSS/TFM | partial | runtime `cmr10.tfm` widths/heights/depths/kern pairs and ff/fi/fl/ffi/ffl ligatures; text faces embed Liberation Serif/Mono as Type0 CID fonts with Identity-H, ToUnicode and width arrays; used faces embed per-document TrueType glyf subsets that keep the original glyph IDs, include composite components, and carry a matching ToUnicode CMap; ASCII documents use the compact tier; no Base-14 dependency; SVG carries family/weight/style; route-D PDFs embed Knuth's Computer Modern Type1 programs (cmr10/cmbx10/cmti10/cmbxti10/cmtt10/cmss10/cmssbx10/cmssi10/cmcsc10/cmsl10/cmbxsl10/cmitt10) as `/Subtype /Type1` fonts with `/FontFile` (`Length1/2/3`), `/Encoding /Differences` and TFM `/Widths`, falling back per glyph to a Liberation subset when a character is outside the encoding while the rest of the face stays in Computer Modern |
|
||||||
| M6 specials/XObject | partial | raw specials, RGB image XObjects, URI link annotations; route-D reads `\documentclass` size options (10/11/12pt) into the paragraph base size and `\baselineskip`, executes `\newcommand`/`\renewcommand` macros textually (with numbered arguments, one `[default]` optional first argument and an eight-pass recursion guard), and expands `geometry`, `\setlength`, title/author/date, `\maketitle`, sectioning, theorem, float and bibliography markup; local `.cls`/`.sty` files are inlined, execute their `\DeclareOption` subset for the options given on `\documentclass`/`\usepackage`, and recurse through local `\LoadClass` bases, while full class layout execution remains absent |
|
| M6 specials/XObject | partial | raw specials, RGB image XObjects, URI link annotations; route-D reads `\documentclass` size options (10/11/12pt) into the paragraph base size and `\baselineskip`, executes `\newcommand`/`\renewcommand` macros textually (with numbered arguments, one `[default]` optional first argument and an eight-pass recursion guard), and expands `geometry`, `\setlength`, title/author/date, `\maketitle`, sectioning, theorem, float and bibliography markup; local `.cls`/`.sty` files are inlined, execute their `\DeclareOption` subset for the options given on `\documentclass`/`\usepackage`, and recurse through local `\LoadClass` bases, while full class layout execution remains absent |
|
||||||
| M7 incremental integration | partial | route-D preview/PDF/edit endpoints plus opt-in `?engine=route-d` project preview, content-based page hashes and section/emphasis/display-math/inline-math/itemize/enumerate/description/quote/center/flushleft/flushright mapping; editor toggle in `texrra-web`; project route-D previews are memoised by a hash of the expanded source (32 entries) and invalidated automatically when the source changes; project route-D PDF exports are cached by the same expanded-source hash (eight entries) and report `X-Texrra-Cache: hit`/`miss`; the flat `POST /api/route-d/preview` and `/api/route-d/pdf` endpoints likewise memoise the last 32 previews and eight PDFs by source hash and report the same header; malformed sources answer 422 with a JSON `{"error": "..."}` body and never populate either cache, and four concurrent identical flat previews share a single mutex-protected cache entry and return identical bodies; a deployment can default to route-D with `TEXRRA_ENGINE=route-d`, and an explicit `?engine=` overrides that default for both project previews and PDFs (v1 and route-d alike; covered by an engine-parameter matrix test); inline `$...$`/`\(...\)` math is laid out inside 10pt paragraphs, while larger paragraphs keep delimiters literal; `\href` labels paint PDF `/Link` URI annotations over their runs |
|
| M7 incremental integration | partial | route-D preview/PDF/edit endpoints plus opt-in `?engine=route-d` project preview, content-based page hashes and section/emphasis/display-math/inline-math/itemize/enumerate/description/quote/center/flushleft/flushright mapping; editor toggle in `texrra-web`; project route-D previews are memoised by a hash of the expanded source (32 entries) and invalidated automatically when the source changes; project route-D PDF exports are cached by the same expanded-source hash (eight entries) and report `X-Texrra-Cache: hit`/`miss`; the flat `POST /api/route-d/preview` and `/api/route-d/pdf` endpoints likewise memoise the last 32 previews and eight PDFs by source hash and report the same header; malformed sources answer 422 with a JSON `{"error": "..."}` body and never populate either cache, and four concurrent identical flat previews (or three flat PDFs) share a single mutex-protected cache entry and return identical bodies; a deployment can default to route-D with `TEXRRA_ENGINE=route-d`, and an explicit `?engine=` overrides that default for both project previews and PDFs (v1 and route-d alike; covered by an engine-parameter matrix test); inline `$...$`/`\(...\)` math is laid out inside 10pt paragraphs, while larger paragraphs keep delimiters literal; `\href` labels paint PDF `/Link` URI annotations over their runs |
|
||||||
|
|
||||||
v1 remains the production renderer; the route-D core is additive and tested independently.
|
v1 remains the production renderer; the route-D core is additive and tested independently.
|
||||||
|
|
||||||
@@ -367,7 +367,7 @@ Math coverage includes fractions/roots, scripts, `\left...\right` with body-scal
|
|||||||
|
|
||||||
Paragraph units carry a `ParagraphFont`; `Unit::paragraph_with_face` and `Unit::paragraph_with_style_and_face` select Roman, bold, italic, mono, or sans. The corresponding Computer Modern TFM (`cmr10`, `cmbx10`, `cmti10`, `cmbxti10`, `cmtt10`, `cmss10`, `cmssbx10`, `cmssi10`, `cmcsc10`) supplies advances, kerns, ligatures, and italic correction for layout, the display list selects the matching face, and the PDF writes Computer Modern Type1 outlines for each built-in face (`cmr10`/`cmbx10`/`cmti10`/`cmbxti10`/`cmtt10`/`cmss10`/`cmssbx10`/`cmssi10`/`cmcsc10`, plus `cmmi10` for mathematical italic letters, `cmsy10` for math symbols and `cmex10` for big operators), falling back to Liberation subsets only for characters the Type1 encodings cannot address; those fallback glyphs keep their Unicode text under PDF extraction, so accented and Greek words round-trip; Type1 faces carry a ToUnicode CMap built from the requested characters, so glyphs whose names are ambiguous in the Adobe Glyph List (capital Omega, which would otherwise extract as U+2126) keep their intended code points. `Engine::edit` preserves the face when reflowing an edited paragraph.
|
Paragraph units carry a `ParagraphFont`; `Unit::paragraph_with_face` and `Unit::paragraph_with_style_and_face` select Roman, bold, italic, mono, or sans. The corresponding Computer Modern TFM (`cmr10`, `cmbx10`, `cmti10`, `cmbxti10`, `cmtt10`, `cmss10`, `cmssbx10`, `cmssi10`, `cmcsc10`) supplies advances, kerns, ligatures, and italic correction for layout, the display list selects the matching face, and the PDF writes Computer Modern Type1 outlines for each built-in face (`cmr10`/`cmbx10`/`cmti10`/`cmbxti10`/`cmtt10`/`cmss10`/`cmssbx10`/`cmssi10`/`cmcsc10`, plus `cmmi10` for mathematical italic letters, `cmsy10` for math symbols and `cmex10` for big operators), falling back to Liberation subsets only for characters the Type1 encodings cannot address; those fallback glyphs keep their Unicode text under PDF extraction, so accented and Greek words round-trip; Type1 faces carry a ToUnicode CMap built from the requested characters, so glyphs whose names are ambiguous in the Adobe Glyph List (capital Omega, which would otherwise extract as U+2126) keep their intended code points. `Engine::edit` preserves the face when reflowing an edited paragraph.
|
||||||
|
|
||||||
The crate currently has 411 unit tests plus ten route-D integration tests and thirty-five oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 777 tests (411 route-D unit, 188 engine binary unit, 10 route-D integration, 35 oracle, 71 v1 integration, 57 server, 4 engine unit, 1 core unit), with none ignored. v1 remains the live server path.
|
The crate currently has 411 unit tests plus ten route-D integration tests and thirty-five oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 778 tests (411 route-D unit, 188 engine binary unit, 10 route-D integration, 35 oracle, 71 v1 integration, 58 server, 4 engine unit, 1 core unit), with none ignored. v1 remains the live server path.
|
||||||
|
|
||||||
### M0 incremental demo
|
### M0 incremental demo
|
||||||
|
|
||||||
|
|||||||
+49
-11
@@ -132,21 +132,24 @@ impl TestServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn request(&self, method: &str, path: &str, body: &[u8], content_type: &str) -> Response {
|
fn request(&self, method: &str, path: &str, body: &[u8], content_type: &str) -> Response {
|
||||||
|
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) {
|
match send(self.port, method, path, body, content_type) {
|
||||||
Ok(response) => response,
|
Ok(response) => return response,
|
||||||
Err(first) => {
|
Err(error) => errors.push(error.to_string()),
|
||||||
std::thread::sleep(Duration::from_millis(200));
|
}
|
||||||
match send(self.port, method, path, body, content_type) {
|
}
|
||||||
Ok(response) => response,
|
panic!(
|
||||||
Err(second) => panic!(
|
"HTTP request failed {} times: {}
|
||||||
"HTTP request failed twice: {first}; {second}
|
|
||||||
server log:
|
server log:
|
||||||
{}",
|
{}",
|
||||||
|
errors.len(),
|
||||||
|
errors.join("; "),
|
||||||
self.log()
|
self.log()
|
||||||
),
|
);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get(&self, path: &str) -> Response {
|
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"));
|
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 {
|
fn text_x(svg: &str, needle: &str) -> f64 {
|
||||||
let index = svg.find(needle).expect("text run");
|
let index = svg.find(needle).expect("text run");
|
||||||
let prefix = &svg[..index];
|
let prefix = &svg[..index];
|
||||||
|
|||||||
Reference in new issue
Block a user