Skip to content

Commit 6a11d04

Browse files
committed
test: Remove integration-test logic from production build
1 parent 9751a20 commit 6a11d04

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

Justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ venv version=PYTHON_DEFAULT_VERSION:
3131

3232
# Build the module in dev mode
3333
dev:
34-
uv run --directory codetracer-python-recorder maturin develop --uv
34+
uv run --directory codetracer-python-recorder maturin develop --uv --features integration-test
3535

3636
# Run unit tests of dev build
3737
test: cargo-test py-test

codetracer-python-recorder/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ crate-type = ["cdylib", "rlib"]
1717

1818
[features]
1919
extension-module = ["pyo3/extension-module"]
20+
integration-test = []
2021
default = ["extension-module"]
2122

2223
[dependencies]

codetracer-python-recorder/src/runtime/mod.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ use value_capture::{capture_call_arguments, record_return_value, record_visible_
1717
use std::collections::{hash_map::Entry, HashMap, HashSet};
1818
use std::fs;
1919
use std::path::{Path, PathBuf};
20+
#[cfg(feature = "integration-test")]
2021
use std::sync::atomic::{AtomicBool, Ordering};
22+
#[cfg(feature = "integration-test")]
2123
use std::sync::OnceLock;
2224

2325
use pyo3::prelude::*;
@@ -89,15 +91,20 @@ impl FailureStage {
8991
}
9092
}
9193

94+
// Failure injection helpers are only compiled for integration tests.
95+
#[cfg_attr(not(feature = "integration-test"), allow(dead_code))]
9296
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
9397
enum FailureMode {
9498
Stage(FailureStage),
9599
SuppressEvents,
96100
}
97101

102+
#[cfg(feature = "integration-test")]
98103
static FAILURE_MODE: OnceLock<Option<FailureMode>> = OnceLock::new();
104+
#[cfg(feature = "integration-test")]
99105
static FAILURE_TRIGGERED: AtomicBool = AtomicBool::new(false);
100106

107+
#[cfg(feature = "integration-test")]
101108
fn configured_failure_mode() -> Option<FailureMode> {
102109
*FAILURE_MODE.get_or_init(|| {
103110
let raw = std::env::var("CODETRACER_TEST_INJECT_FAILURE").ok();
@@ -114,6 +121,7 @@ fn configured_failure_mode() -> Option<FailureMode> {
114121
})
115122
}
116123

124+
#[cfg(feature = "integration-test")]
117125
fn should_inject_failure(stage: FailureStage) -> bool {
118126
match configured_failure_mode() {
119127
Some(FailureMode::Stage(mode)) if mode == stage => {
@@ -123,10 +131,22 @@ fn should_inject_failure(stage: FailureStage) -> bool {
123131
}
124132
}
125133

134+
#[cfg(not(feature = "integration-test"))]
135+
fn should_inject_failure(_stage: FailureStage) -> bool {
136+
false
137+
}
138+
139+
#[cfg(feature = "integration-test")]
126140
fn suppress_events() -> bool {
127141
matches!(configured_failure_mode(), Some(FailureMode::SuppressEvents))
128142
}
129143

144+
#[cfg(not(feature = "integration-test"))]
145+
fn suppress_events() -> bool {
146+
false
147+
}
148+
149+
#[cfg(feature = "integration-test")]
130150
fn injected_failure_err(stage: FailureStage) -> PyErr {
131151
let err = bug!(
132152
ErrorCode::TraceIncomplete,
@@ -137,6 +157,17 @@ fn injected_failure_err(stage: FailureStage) -> PyErr {
137157
ffi::map_recorder_error(err)
138158
}
139159

160+
#[cfg(not(feature = "integration-test"))]
161+
fn injected_failure_err(stage: FailureStage) -> PyErr {
162+
let err = bug!(
163+
ErrorCode::TraceIncomplete,
164+
"failure injection requested at {} without fail-injection feature",
165+
stage.as_str()
166+
)
167+
.with_context("injection_stage", stage.as_str().to_string());
168+
ffi::map_recorder_error(err)
169+
}
170+
140171
fn is_real_filename(filename: &str) -> bool {
141172
let trimmed = filename.trim();
142173
!(trimmed.starts_with('<') && trimmed.ends_with('>'))

0 commit comments

Comments
 (0)