STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
test_cea_build_gate.py
Go to the documentation of this file.
1
"""A missing/stale CEA cache must FAIL FAST where in-process builds are disabled.
2
3
Root cause of a production crash: switching to a propellant whose cache was not
4
committed (kerolox) made a request handler start a cold CEA build -- ~n_points^3
5
rocketcea calls whose growing in-process cache took the host to >12 GB. Builds
6
are an offline job (regenerate-cea-cache.yml); the deployed server disables them
7
by setting ED_ALLOW_CEA_BUILD=0 (docker-compose.yml) and must instead raise
8
immediately on a missing cache.
9
10
The gate is environment-based (env var), not code-path based, because local dev
11
runs the same backend over localhost and must keep building on demand. These
12
tests pin both directions.
13
"""
14
15
import
os
16
import
unittest
17
from
pathlib
import
Path
18
19
from
engine.pipeline.io
import
load_config
20
from
engine.pipeline.config_switch
import
switch_config
21
from
engine.pipeline.config_schemas
import
PintleEngineConfig
22
from
engine.pipeline
import
cea_cache
23
from
engine.pipeline.cea_cache
import
CEACache
24
25
ROOT = Path(__file__).resolve().parents[1]
26
BOGUS_CACHE =
"/tmp/__ed_gate_test_should_never_be_written.npz"
27
28
29
class
TestCeaBuildGate
(unittest.TestCase):
30
def
setUp
(self):
31
# A kerolox CEA identity pointed at a cache path that does not exist, so
32
# any construction would otherwise fall through to a cold build.
33
base = load_config(str(ROOT /
"configs"
/
"default.yaml"
)).model_dump(mode=
"json"
)
34
kero = switch_config(base, propellant_preset=
"kerolox"
)
35
kero[
"combustion"
][
"cea"
][
"cache_file"
] = BOGUS_CACHE
36
self.
cea_cfg
=
PintleEngineConfig
(**kero).combustion.cea
37
self.
_saved_env
= os.environ.get(
"ED_ALLOW_CEA_BUILD"
)
38
Path(BOGUS_CACHE).unlink(missing_ok=
True
)
39
40
def
tearDown
(self):
41
if
self.
_saved_env
is
None
:
42
os.environ.pop(
"ED_ALLOW_CEA_BUILD"
,
None
)
43
else
:
44
os.environ[
"ED_ALLOW_CEA_BUILD"
] = self.
_saved_env
45
Path(BOGUS_CACHE).unlink(missing_ok=
True
)
46
47
def
test_build_gate_reads_env
(self):
48
# Default (unset) allows building; the server's "0" disallows it; an
49
# explicit "1" re-enables (the escape hatch).
50
os.environ.pop(
"ED_ALLOW_CEA_BUILD"
,
None
)
51
self.assertTrue(cea_cache._cea_build_allowed())
52
os.environ[
"ED_ALLOW_CEA_BUILD"
] =
"0"
53
self.assertFalse(cea_cache._cea_build_allowed())
54
os.environ[
"ED_ALLOW_CEA_BUILD"
] =
"1"
55
self.assertTrue(cea_cache._cea_build_allowed())
56
57
def
test_missing_cache_fails_fast_when_builds_disabled
(self):
58
# Production posture: builds off. A missing cache must raise immediately
59
# (not spend hours building and blow up memory), and write nothing.
60
os.environ[
"ED_ALLOW_CEA_BUILD"
] =
"0"
61
with
self.assertRaises(RuntimeError)
as
ctx:
62
CEACache
(self.
cea_cfg
)
63
msg = str(ctx.exception)
64
self.assertIn(
"RP-1"
, msg)
65
self.assertIn(
"ED_ALLOW_CEA_BUILD"
, msg)
66
self.assertFalse(
67
Path(BOGUS_CACHE).exists(),
68
"a disabled build must not write a cache file"
,
69
)
70
71
72
if
__name__ ==
"__main__"
:
73
unittest.main()
engine.pipeline.cea_cache.CEACache
Definition
cea_cache.py:326
engine.pipeline.config_schemas.PintleEngineConfig
Definition
config_schemas.py:2735
test_cea_build_gate.TestCeaBuildGate
Definition
test_cea_build_gate.py:29
test_cea_build_gate.TestCeaBuildGate.test_missing_cache_fails_fast_when_builds_disabled
test_missing_cache_fails_fast_when_builds_disabled(self)
Definition
test_cea_build_gate.py:57
test_cea_build_gate.TestCeaBuildGate.cea_cfg
cea_cfg
Definition
test_cea_build_gate.py:36
test_cea_build_gate.TestCeaBuildGate._saved_env
_saved_env
Definition
test_cea_build_gate.py:37
test_cea_build_gate.TestCeaBuildGate.test_build_gate_reads_env
test_build_gate_reads_env(self)
Definition
test_cea_build_gate.py:47
engine.pipeline.cea_cache
Definition
cea_cache.py:1
engine.pipeline.config_schemas
Definition
config_schemas.py:1
engine.pipeline.config_switch
Definition
config_switch.py:1
engine.pipeline.io
Definition
io.py:1
engine.pipeline
Definition
__init__.py:1
setUp
void setUp(void)
Definition
test_main.cpp:17
tearDown
void tearDown(void)
Definition
test_main.cpp:20
EngineDesign
tests
test_cea_build_gate.py
Generated by
1.15.0