pub struct TestContext { /* private fields */ }Expand description
Test context wrapper providing convenient testing utilities.
Wraps Cx::for_testing() and provides helper methods for:
- Budget/timeout configuration
- Creating
McpContextinstances - Running async operations with cleanup
§Example
ⓘ
let ctx = TestContext::new();
let mcp_ctx = ctx.mcp_context(1); // Request ID 1
// With custom budget
let ctx = TestContext::new().with_budget_secs(30);Implementations§
Source§impl TestContext
impl TestContext
Sourcepub fn with_budget_secs(self, secs: u64) -> Self
pub fn with_budget_secs(self, secs: u64) -> Self
Sourcepub fn with_budget_ms(self, ms: u64) -> Self
pub fn with_budget_ms(self, ms: u64) -> Self
Creates a test context with a budget timeout in milliseconds.
§Arguments
ms- Timeout in milliseconds
Sourcepub fn with_session_state(self, state: SessionState) -> Self
pub fn with_session_state(self, state: SessionState) -> Self
Creates a test context with shared session state.
Useful for testing state persistence across multiple contexts.
§Example
ⓘ
let state = SessionState::new();
let ctx1 = TestContext::new().with_session_state(state.clone());
let ctx2 = TestContext::new().with_session_state(state.clone());
// Both contexts share the same session stateSourcepub fn mcp_context(&self, request_id: u64) -> McpContext
pub fn mcp_context(&self, request_id: u64) -> McpContext
Sourcepub fn mcp_context_with_state(
&self,
request_id: u64,
state: SessionState,
) -> McpContext
pub fn mcp_context_with_state( &self, request_id: u64, state: SessionState, ) -> McpContext
Creates an McpContext with shared session state.
§Arguments
request_id- The request IDstate- Session state to attach
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Checks if cancellation has been requested.
Sourcepub fn checkpoint(&self) -> McpResult<()>
pub fn checkpoint(&self) -> McpResult<()>
Performs a cancellation checkpoint.
Returns Err(CancelledError) if cancellation was requested.
Trait Implementations§
Source§impl Clone for TestContext
impl Clone for TestContext
Source§fn clone(&self) -> TestContext
fn clone(&self) -> TestContext
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TestContext
impl Debug for TestContext
Auto Trait Implementations§
impl Freeze for TestContext
impl !RefUnwindSafe for TestContext
impl Send for TestContext
impl Sync for TestContext
impl Unpin for TestContext
impl !UnwindSafe for TestContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).