Skip to content

Commit fd55dfc

Browse files
committed
cleanup - gate compilation at module and call site, use dbg_panic macro at state machines instead of direct calls to antithesis assert_always (dbg_panic just logs in non-release builds with no antithesis_assertions feature flag anyways)
1 parent c573904 commit fd55dfc

File tree

6 files changed

+28
-88
lines changed

6 files changed

+28
-88
lines changed

crates/sdk-core/src/abstractions.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -422,11 +422,12 @@ impl<SK: SlotKind> OwnedMeteredSemPermit<SK> {
422422
#[derive(Debug)]
423423
pub(crate) struct UsedMeteredSemPermit<SK: SlotKind>(#[allow(dead_code)] OwnedMeteredSemPermit<SK>);
424424

425-
#[cfg(feature = "antithesis_assertions")]
426425
macro_rules! dbg_panic {
427426
($($arg:tt)*) => {{
428427
let message = format!($($arg)*);
429428
error!("{}", message);
429+
430+
#[cfg(feature = "antithesis_assertions")]
430431
crate::antithesis::assert_always!(
431432
false,
432433
"dbg_panic invariant triggered",
@@ -440,14 +441,6 @@ macro_rules! dbg_panic {
440441
debug_assert!(false, "{}", message);
441442
}};
442443
}
443-
444-
#[cfg(not(feature = "antithesis_assertions"))]
445-
macro_rules! dbg_panic {
446-
($($arg:tt)*) => {{
447-
error!($($arg)*);
448-
debug_assert!(false, $($arg)*);
449-
}};
450-
}
451444
pub(crate) use dbg_panic;
452445

453446
pub(crate) struct ActiveCounter<F: Fn(usize)>(watch::Sender<usize>, Option<Arc<F>>);

crates/sdk-core/src/antithesis.rs

Lines changed: 20 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,29 @@
22
//!
33
//! This module provides assertion macros that integrate with the Antithesis
44
//! testing platform to detect invariant violations during fuzz testing.
5-
//!
6-
//! When the `antithesis_assertions` feature is disabled, assertions compile
7-
//! to no-ops.
8-
9-
#[cfg(feature = "antithesis_assertions")]
10-
mod enabled {
11-
use std::sync::OnceLock;
12-
13-
/// Ensure Antithesis is initialized exactly once.
14-
pub(crate) fn ensure_init() {
15-
static INIT: OnceLock<()> = OnceLock::new();
16-
INIT.get_or_init(|| {
17-
::antithesis_sdk::antithesis_init();
18-
});
19-
}
205
21-
/// Assert that a condition is always true during Antithesis fuzz testing.
22-
/// Use `false` as the condition to log an invariant violation.
23-
macro_rules! assert_always {
24-
($condition:expr, $message:literal, $details:expr) => {{
25-
$crate::antithesis::ensure_init();
26-
let details: ::serde_json::Value = $details;
27-
::antithesis_sdk::assert_always!($condition, $message, &details);
28-
}};
29-
($condition:expr, $message:literal) => {{
30-
$crate::antithesis::ensure_init();
31-
::antithesis_sdk::assert_always!($condition, $message);
32-
}};
33-
}
6+
use std::sync::OnceLock;
347

35-
pub(crate) use assert_always;
8+
/// Ensure Antithesis is initialized exactly once.
9+
pub(crate) fn ensure_init() {
10+
static INIT: OnceLock<()> = OnceLock::new();
11+
INIT.get_or_init(|| {
12+
::antithesis_sdk::antithesis_init();
13+
});
3614
}
3715

38-
#[cfg(not(feature = "antithesis_assertions"))]
39-
mod disabled {
40-
/// No-op when feature is disabled.
41-
#[inline(always)]
42-
pub(crate) fn ensure_init() {}
43-
44-
/// No-op assertion when feature is disabled.
45-
macro_rules! assert_always {
46-
($condition:expr, $message:literal, $details:expr) => {{
47-
let _ = ($condition, $message);
48-
let _ = $details;
49-
}};
50-
($condition:expr, $message:literal) => {{
51-
let _ = ($condition, $message);
52-
}};
53-
}
54-
55-
pub(crate) use assert_always;
16+
/// Assert that a condition is always true during Antithesis fuzz testing.
17+
/// Use `false` as the condition to log an invariant violation.
18+
macro_rules! assert_always {
19+
($condition:expr, $message:literal, $details:expr) => {{
20+
$crate::antithesis::ensure_init();
21+
let details: ::serde_json::Value = $details;
22+
::antithesis_sdk::assert_always!($condition, $message, &details);
23+
}};
24+
($condition:expr, $message:literal) => {{
25+
$crate::antithesis::ensure_init();
26+
::antithesis_sdk::assert_always!($condition, $message);
27+
}};
5628
}
5729

58-
#[cfg(feature = "antithesis_assertions")]
59-
pub(crate) use enabled::*;
60-
61-
#[cfg(not(feature = "antithesis_assertions"))]
62-
pub(crate) use disabled::*;
30+
pub(crate) use assert_always;

crates/sdk-core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ extern crate tracing;
1212
extern crate core;
1313

1414
mod abstractions;
15+
#[cfg(feature = "antithesis_assertions")]
1516
mod antithesis;
1617
#[cfg(feature = "debug-plugin")]
1718
pub mod debug_client;

crates/sdk-core/src/worker/workflow/machines/activity_state_machine.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,7 @@ impl ActivityMachine {
194194
vec![self.create_cancelation_resolve(details).into()]
195195
}
196196
x => {
197-
crate::antithesis::assert_always!(
198-
false,
199-
"activity cancel yields supported command",
200-
::serde_json::json!({
201-
"activity_seq": self.shared_state.attrs.seq,
202-
"unexpected_command": format!("{x:?}"),
203-
"state": self.state().to_string(),
204-
})
205-
);
197+
dbg_panic!("Invalid cancel event response {x:?}");
206198
panic!("Invalid cancel event response {x:?}");
207199
}
208200
})

crates/sdk-core/src/worker/workflow/machines/child_workflow_state_machine.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use super::{
33
WFMachinesAdapter, WFMachinesError, fsm, workflow_machines::MachineResponse,
44
};
55
use crate::{
6+
abstractions::dbg_panic,
67
internal_flags::CoreInternalFlags,
78
worker::workflow::{InternalFlagsRef, machines::HistEventData},
89
};
@@ -497,16 +498,7 @@ impl ChildWorkflowMachine {
497498
self.adapt_response(c, None)
498499
}
499500
x => {
500-
crate::antithesis::assert_always!(
501-
false,
502-
"child workflow cancel yields supported command",
503-
::serde_json::json!({
504-
"workflow_id": self.shared_state.workflow_id.clone(),
505-
"run_id": self.shared_state.run_id.clone(),
506-
"unexpected_command": format!("{x:?}"),
507-
"state": self.state().to_string(),
508-
})
509-
);
501+
dbg_panic!("Invalid cancel event response {x:?}");
510502
panic!("Invalid cancel event response {x:?}");
511503
}
512504
})

crates/sdk-core/src/worker/workflow/machines/complete_workflow_state_machine.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::{
22
EventInfo, NewMachineWithCommand, OnEventWrapper, StateMachine, TransitionResult,
33
WFMachinesAdapter, WFMachinesError, fsm, workflow_machines::MachineResponse,
44
};
5-
use crate::worker::workflow::machines::HistEventData;
5+
use crate::{abstractions::dbg_panic, worker::workflow::machines::HistEventData};
66
use std::convert::TryFrom;
77
use temporalio_common::protos::{
88
coresdk::workflow_commands::CompleteWorkflowExecution,
@@ -42,13 +42,7 @@ pub(super) fn complete_workflow(attribs: CompleteWorkflowExecution) -> NewMachin
4242
{
4343
Some(CompleteWFCommand::AddCommand(c)) => c,
4444
unexpected => {
45-
crate::antithesis::assert_always!(
46-
false,
47-
"complete workflow scheduling yields command",
48-
::serde_json::json!({
49-
"unexpected": format!("{unexpected:?}"),
50-
})
51-
);
45+
dbg_panic!("complete wf machine on_schedule must produce command: {unexpected:?}");
5246
panic!("complete wf machine on_schedule must produce command");
5347
}
5448
};

0 commit comments

Comments
 (0)