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.
Provides an isolated testing environment for jobs with progress tracking, retry simulation, cancellation testing, and HTTP mocking.
§Example
let ctx = TestJobContext::builder("export_users")
.with_job_id(Uuid::new_v4())
.build();
// Simulate progress
ctx.progress(50, "Halfway there")?;
// Verify progress was recorded
assert_eq!(ctx.progress_updates().len(), 1);
// Test cancellation
ctx.request_cancellation();
assert!(ctx.is_cancel_requested().unwrap());Fields§
§job_id: UuidJob ID.
job_type: StringJob type name.
attempt: u32Current attempt number (1-based).
max_attempts: u32Maximum attempts allowed.
auth: AuthContextAuthentication context.
Implementations§
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 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 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
Source§fn env_provider(&self) -> &dyn EnvProvider
fn env_provider(&self) -> &dyn EnvProvider
Source§fn env_or(&self, key: &str, default: &str) -> String
fn env_or(&self, key: &str, default: &str) -> String
Source§fn env_require(&self, key: &str) -> Result<String>
fn env_require(&self, key: &str) -> Result<String>
Source§fn env_parse<T: FromStr>(&self, key: &str) -> Result<T>
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>
Source§fn env_contains(&self, key: &str) -> bool
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 !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