claude-connector: bound serve_config_with fail-closed test wait
Run negative serve_config_with cases on a bounded thread so a mutant that enters serve_service fails in seconds rather than hanging until timeout.
This commit is contained in:
parent
0098e3d23d
commit
c0386bbcd5
1 changed files with 36 additions and 25 deletions
|
|
@ -1116,6 +1116,31 @@ mod tests {
|
|||
// SAFETY: guarded by CREDENTIALS_ENV_LOCK across all in-process tests touching CREDENTIALS_DIRECTORY.
|
||||
unsafe { std::env::set_var("CREDENTIALS_DIRECTORY", &creds) };
|
||||
|
||||
let assert_fails_closed = |config: &ClaudeConnectorConfig, label: &str| {
|
||||
write_config(&cfg_path, config).unwrap();
|
||||
let (done_tx, done_rx) = std::sync::mpsc::channel();
|
||||
let (started_tx, started_rx) = std::sync::mpsc::channel();
|
||||
let path = cfg_path.clone();
|
||||
std::thread::spawn(move || {
|
||||
let res = serve_config_with(&path, |_| {
|
||||
let _ = started_tx.send(());
|
||||
});
|
||||
let _ = done_tx.send(res);
|
||||
});
|
||||
let result = done_rx
|
||||
.recv_timeout(Duration::from_secs(5))
|
||||
.unwrap_or_else(|_| {
|
||||
panic!(
|
||||
"serve_config_with did not fail closed for {label} (started={})",
|
||||
started_rx.try_recv().is_ok()
|
||||
)
|
||||
});
|
||||
assert!(
|
||||
matches!(result, Err(ConfigError::Unusable("providers"))),
|
||||
"expected Unusable(\"providers\") for {label}, got {result:?}"
|
||||
);
|
||||
};
|
||||
|
||||
// Keyless loopback passes readiness_of_in and fails closed in serve_config_with.
|
||||
let keyless_loopback = make_config(
|
||||
vec![messages_entry(
|
||||
|
|
@ -1126,11 +1151,7 @@ mod tests {
|
|||
crate::messages::PROVIDER,
|
||||
);
|
||||
assert!(readiness_of_in(&keyless_loopback, None).is_ok());
|
||||
write_config(&cfg_path, &keyless_loopback).unwrap();
|
||||
assert!(matches!(
|
||||
serve_config_with(&cfg_path, |_| ()),
|
||||
Err(ConfigError::Unusable("providers"))
|
||||
));
|
||||
assert_fails_closed(&keyless_loopback, "keyless loopback");
|
||||
|
||||
// Custom base_url (loopback or HTTPS) with credential also fails closed in serve_config_with.
|
||||
for custom_url in ["http://127.0.0.1:18080", "https://staging.example.test"] {
|
||||
|
|
@ -1142,14 +1163,7 @@ mod tests {
|
|||
)],
|
||||
crate::messages::PROVIDER,
|
||||
);
|
||||
write_config(&cfg_path, &custom).unwrap();
|
||||
assert!(
|
||||
matches!(
|
||||
serve_config_with(&cfg_path, |_| ()),
|
||||
Err(ConfigError::Unusable("providers"))
|
||||
),
|
||||
"expected Unusable(\"providers\") for {custom_url}"
|
||||
);
|
||||
assert_fails_closed(&custom, custom_url);
|
||||
}
|
||||
|
||||
// Non-matching id or multi-provider config fails closed in serve_config_with.
|
||||
|
|
@ -1161,11 +1175,7 @@ mod tests {
|
|||
)],
|
||||
"custom-messages",
|
||||
);
|
||||
write_config(&cfg_path, &wrong_id).unwrap();
|
||||
assert!(matches!(
|
||||
serve_config_with(&cfg_path, |_| ()),
|
||||
Err(ConfigError::Unusable("providers"))
|
||||
));
|
||||
assert_fails_closed(&wrong_id, "wrong_id");
|
||||
|
||||
let multi = make_config(
|
||||
vec![
|
||||
|
|
@ -1178,11 +1188,7 @@ mod tests {
|
|||
],
|
||||
crate::messages::PROVIDER,
|
||||
);
|
||||
write_config(&cfg_path, &multi).unwrap();
|
||||
assert!(matches!(
|
||||
serve_config_with(&cfg_path, |_| ()),
|
||||
Err(ConfigError::Unusable("providers"))
|
||||
));
|
||||
assert_fails_closed(&multi, "multi-provider");
|
||||
|
||||
// Default ENDPOINT + credential with matching id serves cleanly.
|
||||
let valid_messages = make_config(
|
||||
|
|
@ -1204,10 +1210,15 @@ mod tests {
|
|||
});
|
||||
let deadline = std::time::Instant::now() + Duration::from_secs(10);
|
||||
while !*started_flag.lock().unwrap() {
|
||||
if served.is_finished() {
|
||||
panic!(
|
||||
"serve_config_with exited before starting for valid AnthropicMessages: {:?}",
|
||||
served.join()
|
||||
);
|
||||
}
|
||||
assert!(
|
||||
std::time::Instant::now() < deadline,
|
||||
"serve_config_with never started for valid AnthropicMessages: {:?}",
|
||||
served.is_finished()
|
||||
"serve_config_with never started for valid AnthropicMessages"
|
||||
);
|
||||
std::thread::sleep(Duration::from_millis(10));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue