subagent: fix a real test race on the process-wide OTEL_RESOURCE_ATTRIBUTES env var
This commit is contained in:
parent
1ad7145cc5
commit
d26b754701
1 changed files with 14 additions and 11 deletions
|
|
@ -443,10 +443,21 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
// One test, not two: `subagent_otel_attrs` reads the real process-wide
|
||||
// `OTEL_RESOURCE_ATTRIBUTES` env var, and cargo runs tests in parallel
|
||||
// threads by default — two separate tests each mutating that global
|
||||
// raced each other (and, in this container, lost to the agent's own
|
||||
// real ambient value). Sequencing both assertions in one test removes
|
||||
// the race instead of papering over it with a mutex.
|
||||
#[test]
|
||||
fn otel_attrs_appends_when_ambient_var_is_set() {
|
||||
// SAFETY: test-only env mutation, single-threaded within this fn's
|
||||
// scope (no other test in this crate touches this var — checked).
|
||||
fn otel_attrs_append_ambient_value_or_stand_alone() {
|
||||
// SAFETY: test-only env mutation; sequenced within this one test so
|
||||
// no other test's concurrent read/write of the same var can race it.
|
||||
unsafe {
|
||||
std::env::remove_var("OTEL_RESOURCE_ATTRIBUTES");
|
||||
}
|
||||
assert_eq!(subagent_otel_attrs("batch-1"), "subagent=batch-1");
|
||||
|
||||
unsafe {
|
||||
std::env::set_var("OTEL_RESOURCE_ATTRIBUTES", "agent=damocles");
|
||||
}
|
||||
|
|
@ -459,14 +470,6 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn otel_attrs_stands_alone_when_ambient_var_is_unset() {
|
||||
unsafe {
|
||||
std::env::remove_var("OTEL_RESOURCE_ATTRIBUTES");
|
||||
}
|
||||
assert_eq!(subagent_otel_attrs("batch-1"), "subagent=batch-1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_config_only_appends_system_prompt_when_given() {
|
||||
let with = build_config("n", None, Some("/tmp/p.md"));
|
||||
|
|
|
|||
Loading…
Reference in a new issue