1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//! Tests for `api::mod` — extracted from an inline `#[cfg(test)]` block so
//! `mod.rs` stays under the module-size ratchet budget. As a child of the
//! `api` module (`#[cfg(test)] mod mod_tests;` in `mod.rs`), `super`
//! resolves to `api`, so these tests keep private-field access to `IfcAPI`.
//!
//! ## Poisoned-mutex recovery (the contract this file guards)
//!
//! Every `.lock()` on `IfcAPI`'s cache `Mutex` fields recovers via
//! `.unwrap_or_else(std::sync::PoisonError::into_inner)` instead of
//! `.expect(...)`-panicking, so one malformed file's panic no longer bricks a
//! long-lived / multi-tenant `IfcAPI` (e.g. a parser worker reused across many
//! `parse` calls) for the rest of its lifetime. This is safe for the cache
//! slots (`cached_entity_index`, `cached_item_dedup`, `cached_parts_to_skip`,
//! and friends): each is read and then replaced wholesale
//! (`*slot = <freshly built value>` / `slot.take()`), never mutated
//! field-by-field, so a panic while the lock is *held* necessarily happens
//! before that one assignment runs — the guarded value is never torn, only
//! ever the last known-good value or its untouched initial default.
//! `pipeline_diagnostics` is the one exception (`record_batch` mutates its
//! counters in place), but it is best-effort observability only (surfaced via
//! `getPipelineDiagnostics`), never read for control flow or geometry
//! correctness, so recovering there risks at most a one-batch counter
//! undercount versus permanently losing the whole diagnostics channel.
use IfcAPI;
/// A panic on another thread while it holds one of the cache mutexes
/// (e.g. a malformed entity deep in a lazy cache rebuild) must not
/// brick every later call on this `IfcAPI` instance. Poison
/// `cached_entity_index` directly, exactly like a real panicking
/// rebuild would, then assert `clearPrePassCache` — which locks every
/// cache mutex in turn — still returns normally instead of panicking
/// on `.expect("... Mutex poisoned")` (the pre-fix behaviour).
/// `IfcAPI::new()` installs the crate's panic hook (`crate::utils::set_panic_hook`,
/// via `console_error_panic_hook::set_once()` is NOT called directly — see the
/// comment on `IfcAPI::new()`). That hook's analytics location stash makes
/// `js-sys`/`wasm-bindgen` calls with no native implementation, so it MUST stay
/// gated to `target_arch = "wasm32"` — otherwise a panic occurring anywhere
/// after `IfcAPI::new()` under plain `cargo test` (this crate's native test
/// leg) double-panics while already unwinding and SIGABRTs the whole test
/// binary instead of staying a catchable `std::thread::Result::Err`, exactly
/// like the poison-recovery test above already demonstrates end-to-end.