pub struct TestJobContext {
pub job_id: Uuid,
pub job_type: String,
pub attempt: u32,
pub max_attempts: u32,
pub auth: AuthContext,
/* private fields */
}Expand description
Test context for job functions.
Fields§
§job_id: Uuid§job_type: String§attempt: u32§max_attempts: u32§auth: AuthContextImplementations§
Source§impl TestJobContext
impl TestJobContext
Sourcepub fn builder(job_type: impl Into<String>) -> TestJobContextBuilder
pub fn builder(job_type: impl Into<String>) -> TestJobContextBuilder
Create a new builder.
Sourcepub fn progress(&self, percent: u8, message: impl Into<String>) -> Result<()>
pub fn progress(&self, percent: u8, message: impl Into<String>) -> Result<()>
Report job progress.
Sourcepub fn progress_updates(&self) -> Vec<TestProgressUpdate>
pub fn progress_updates(&self) -> Vec<TestProgressUpdate>
Get all progress updates.
Sourcepub fn saved(&self) -> Value
pub fn saved(&self) -> Value
Get all saved job data.
Returns the in-memory data that was written via save().
Sourcepub fn save(&self, key: &str, value: Value) -> Result<()>
pub fn save(&self, key: &str, value: Value) -> Result<()>
Save a key-value pair to job data.
Merges key into the saved data object. Use saved()
to read it back in assertions.
Sourcepub fn is_last_attempt(&self) -> bool
pub fn is_last_attempt(&self) -> bool
Check if this is the last attempt.
Sourcepub async fn heartbeat(&self) -> Result<()>
pub async fn heartbeat(&self) -> Result<()>
Simulate heartbeat (no-op in tests, but records the intent).
Sourcepub fn is_cancel_requested(&self) -> Result<bool>
pub fn is_cancel_requested(&self) -> Result<bool>
Check if cancellation has been requested.
Sourcepub fn check_cancelled(&self) -> Result<()>
pub fn check_cancelled(&self) -> Result<()>
Return an error if cancellation has been requested.
Use this in job handlers to check for cancellation and exit early.
Sourcepub fn request_cancellation(&self)
pub fn request_cancellation(&self)
Request cancellation (for testing cancellation flows).
After calling this, is_cancel_requested() returns true and
check_cancelled() returns an error.
Sourcepub fn dispatch_job<T: Serialize>(
&self,
job_type: &str,
args: &T,
) -> Result<Uuid>
pub fn dispatch_job<T: Serialize>( &self, job_type: &str, args: &T, ) -> Result<Uuid>
Buffer a sub-job dispatch (mirrors JobContext::dispatch_job).
Sourcepub fn start_workflow<T: Serialize>(
&self,
workflow_name: &str,
args: &T,
) -> Result<Uuid>
pub fn start_workflow<T: Serialize>( &self, workflow_name: &str, args: &T, ) -> Result<Uuid>
Buffer a workflow start (mirrors JobContext::start_workflow).
Sourcepub fn dispatched_jobs(&self) -> Vec<(String, Value, Uuid)>
pub fn dispatched_jobs(&self) -> Vec<(String, Value, Uuid)>
Get all dispatched sub-jobs for assertions.
Sourcepub fn started_workflows(&self) -> Vec<(String, Value, Uuid)>
pub fn started_workflows(&self) -> Vec<(String, Value, Uuid)>
Get all started workflows for assertions.
Sourcepub fn env_mock(&self) -> &MockEnvProvider
pub fn env_mock(&self) -> &MockEnvProvider
Get the mock env provider for verification.
Trait Implementations§
Source§impl EnvAccess for TestJobContext
impl EnvAccess for TestJobContext
fn env_provider(&self) -> &dyn EnvProvider
fn env(&self, key: &str) -> Option<String>
fn env_or(&self, key: &str, default: &str) -> String
fn env_require(&self, key: &str) -> Result<String>
fn env_parse<T: FromStr>(&self, key: &str) -> Result<T>
Source§fn env_parse_or<T: FromStr>(&self, key: &str, default: T) -> Result<T>
fn env_parse_or<T: FromStr>(&self, key: &str, default: T) -> Result<T>
fn env_contains(&self, key: &str) -> bool
Auto Trait Implementations§
impl Freeze for TestJobContext
impl !RefUnwindSafe for TestJobContext
impl Send for TestJobContext
impl Sync for TestJobContext
impl Unpin for TestJobContext
impl UnsafeUnpin for TestJobContext
impl !UnwindSafe for TestJobContext
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more