Files
codex-proxy-rs/backend/crates/gateway-core/tests/runtime/publications.rs
T
ZyyandCodex 22a848b360 refactor(backend): clarify ownership and align xai contracts
Separate execution, provider ports, administration, and plugin lifecycle responsibilities.

Fix shutdown ordering, account lock reclamation, multipart cancellation, budget windows, and WebSocket close handling.

Align xAI catalog, reasoning, tools, replay, quota, and cost handling with current Grok contracts and remove legacy fallbacks.

Update API and architecture documentation with regression coverage. Validated backend suites, strict workspace Clippy, isolated PostgreSQL/Redis integration, and real Codex/Grok client flows.

Co-authored-by: Codex <noreply@openai.com>
2026-10-07 19:34:10 +08:00

114 lines
3.5 KiB
Rust

//! 验证扩展发布代次的在途引用保留与故障隔离
use std::sync::{
Arc,
atomic::{AtomicBool, AtomicUsize, Ordering},
};
use gateway_core::{
routing::extensions::{ExtensionSetId, ExtensionSetLease, ExtensionSetReference},
runtime::RuntimeSnapshotHandle,
};
struct Lease {
ready: Arc<AtomicBool>,
dropped: Arc<AtomicUsize>,
}
impl ExtensionSetLease for Lease {
fn is_ready(&self) -> bool {
self.ready.load(Ordering::SeqCst)
}
}
impl Drop for Lease {
fn drop(&mut self) {
self.dropped.fetch_add(1, Ordering::SeqCst);
}
}
#[test]
fn publication_holds_the_generation_until_its_last_inflight_snapshot_is_released() {
let dropped = Arc::new(AtomicUsize::new(0));
let lease = Arc::new(Lease {
ready: Arc::new(AtomicBool::new(true)),
dropped: Arc::clone(&dropped),
});
let reference =
ExtensionSetReference::new(ExtensionSetId::new("generation-one".into()).unwrap(), lease);
let handle =
RuntimeSnapshotHandle::new(super::empty_snapshot(1).with_extensions(Some(reference)));
let inflight = handle.acquire().unwrap();
handle.publish(super::empty_snapshot(2));
assert_eq!(
inflight.extensions().unwrap().id().as_str(),
"generation-one"
);
assert!(handle.acquire().unwrap().extensions().is_none());
assert_eq!(dropped.load(Ordering::SeqCst), 0);
drop(inflight);
assert_eq!(dropped.load(Ordering::SeqCst), 1);
}
#[test]
fn failed_generation_blocks_new_requests_without_destroying_an_inflight_reference() {
let dropped = Arc::new(AtomicUsize::new(0));
let ready = Arc::new(AtomicBool::new(true));
let lease = Arc::new(Lease {
ready: Arc::clone(&ready),
dropped: Arc::clone(&dropped),
});
let handle = RuntimeSnapshotHandle::new(super::empty_snapshot(1).with_extensions(Some(
ExtensionSetReference::new(ExtensionSetId::new("generation-one".into()).unwrap(), lease),
)));
let inflight = handle.acquire().unwrap();
ready.store(false, Ordering::SeqCst);
assert!(handle.acquire().is_err());
let diagnostic = handle
.snapshot_for_diagnostics()
.expect("unready publication remains observable to the control plane");
assert_eq!(diagnostic.revision().get(), 1);
assert_eq!(
diagnostic.extensions().unwrap().id().as_str(),
"generation-one"
);
drop(diagnostic);
assert_eq!(
inflight.extensions().unwrap().id().as_str(),
"generation-one"
);
handle.suspend();
assert_eq!(dropped.load(Ordering::SeqCst), 0);
drop(inflight);
assert_eq!(dropped.load(Ordering::SeqCst), 1);
}
#[test]
fn an_isolated_extension_fault_keeps_new_requests_and_host_health_available() {
use gateway_core::health::{HealthProbe, HealthState};
struct IsolatedFault;
impl ExtensionSetLease for IsolatedFault {
fn is_ready(&self) -> bool {
false
}
fn can_serve(&self) -> bool {
true
}
}
let reference = ExtensionSetReference::new(
ExtensionSetId::new("isolated-fault".into()).unwrap(),
Arc::new(IsolatedFault),
);
assert!(!reference.is_ready());
let handle =
RuntimeSnapshotHandle::new(super::empty_snapshot(1).with_extensions(Some(reference)));
assert!(handle.acquire().is_ok());
assert!(matches!(
futures::executor::block_on(handle.check()),
HealthState::Healthy
));
handle.suspend();
assert!(
handle.acquire().is_err(),
"unconfirmed host configuration still fails closed"
);
}