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
//! Phase 3 — `LargeCacheMode` configuration tests.
//!
//! These tests verify that `LargeCacheMode` variants are stored and retrieved
//! correctly when set via `LargeCacheConfig::mode`. Assertions use the
//! `dbg_large_cache_mode()` test seam rather than side-effects so they are
//! deterministic and safe to run in parallel.
//!
//! Gated on `alloc-core` + `alloc-decommit` (same gate as the cache itself).
#![cfg(all(feature = "alloc-core", feature = "alloc-decommit"))]
use sefer_alloc::{AllocCore, LargeCacheConfig, LargeCacheMode};
// ── test 1 ───────────────────────────────────────────────────────────────────
/// `LargeCacheConfig::mode` sets the stored mode correctly for each variant.
///
/// Each case constructs an `AllocCore` via `new_with_config` with a specific
/// mode and verifies the stored value via `dbg_large_cache_mode()`. Tests are
/// safe to run in parallel (no env-var mutation).
#[test]
fn config_mode_variants() {
let check = |m: LargeCacheMode| {
let cfg = LargeCacheConfig::new().mode(m);
let ac = AllocCore::new_with_config(cfg).expect("primordial");
assert_eq!(
ac.dbg_large_cache_mode(),
m,
"mode({m:?}) must be stored as {m:?}"
);
};
check(LargeCacheMode::Lazy);
check(LargeCacheMode::Background);
check(LargeCacheMode::Both);
}
// ── test 2 ───────────────────────────────────────────────────────────────────
/// The default config (`LargeCacheConfig::new()` with no `.mode()` call)
/// stores `LargeCacheMode::Lazy`.
#[test]
fn default_mode_is_lazy() {
let ac = AllocCore::new_with_config(LargeCacheConfig::new()).expect("primordial");
assert_eq!(
ac.dbg_large_cache_mode(),
LargeCacheMode::Lazy,
"default config must produce Lazy mode"
);
}
// ── test 3 ───────────────────────────────────────────────────────────────────
/// `AllocCore::new()` (no config) uses the default, which is `Lazy`. The
/// stored mode must be a valid variant — not uninitialised garbage.
#[test]
fn lazy_mode_stored_correctly_in_shard() {
let ac = AllocCore::new().expect("primordial");
let mode = ac.dbg_large_cache_mode();
// Verify the mode is one of the three valid variants (not garbage memory).
let is_valid = matches!(
mode,
LargeCacheMode::Lazy | LargeCacheMode::Background | LargeCacheMode::Both
);
assert!(
is_valid,
"dbg_large_cache_mode() must return a valid LargeCacheMode variant; got {mode:?}"
);
}