118 lines
3.7 KiB
Rust
118 lines
3.7 KiB
Rust
use super::*;
|
|
|
|
#[test]
|
|
#[ignore = "requires explicit isolated database.postgres_test"]
|
|
fn concurrent_cron_deduplicates_and_bounds_catchup() {
|
|
fixture(async |case, scope| {
|
|
let mut left = case.executor(scope).await;
|
|
let mut right = case.executor(scope).await;
|
|
let entry = job::Schedule {
|
|
binding: 0,
|
|
target: "demo.account.hourly",
|
|
schema: "zero",
|
|
cron: "* * * * *",
|
|
policy: Policy {
|
|
retries: 1,
|
|
timeout_ms: 50,
|
|
},
|
|
};
|
|
let (first, second) = tokio::join!(
|
|
job::tick(&mut left, scope, &entry, None, NOW),
|
|
job::tick(&mut right, scope, &entry, None, NOW)
|
|
);
|
|
assert_eq!(first.unwrap() + second.unwrap(), 1);
|
|
let claim = job::claim(&mut left, scope, NOW, 1000)
|
|
.await
|
|
.unwrap()
|
|
.unwrap();
|
|
assert_eq!(claim.payload, "null");
|
|
assert!(matches!(
|
|
serde_json::from_str::<Execution>(&claim.execution).unwrap(),
|
|
Execution::System { tenant: None }
|
|
));
|
|
job::complete(&mut left, scope, &claim, NOW + 1)
|
|
.await
|
|
.unwrap();
|
|
assert_eq!(
|
|
job::tick(&mut right, scope, &entry, None, NOW)
|
|
.await
|
|
.unwrap(),
|
|
0
|
|
);
|
|
assert_eq!(
|
|
job::tick(&mut left, scope, &entry, None, NOW + 60000 * 300)
|
|
.await
|
|
.unwrap(),
|
|
256
|
|
);
|
|
assert_eq!(
|
|
job::tick(&mut right, scope, &entry, None, NOW + 60000 * 300)
|
|
.await
|
|
.unwrap(),
|
|
44
|
|
);
|
|
assert_eq!(
|
|
job::tick(&mut left, scope, &entry, None, 0).await.unwrap(),
|
|
0
|
|
);
|
|
let changed = job::Schedule {
|
|
cron: "*/2 * * * *",
|
|
..entry
|
|
};
|
|
assert!(
|
|
job::tick(&mut right, scope, &changed, None, NOW)
|
|
.await
|
|
.is_err()
|
|
);
|
|
assert_eq!(
|
|
case.count(scope, "SELECT COUNT(*) FROM _dever_job_occurrence")
|
|
.await,
|
|
301
|
|
);
|
|
});
|
|
}
|
|
|
|
#[test]
|
|
#[ignore = "requires explicit isolated database.postgres_test"]
|
|
fn failed_scheduled_enqueue_rolls_back_cursor_and_occurrence() {
|
|
fixture(async |case, scope| {
|
|
let mut executor = case.executor(scope).await;
|
|
executor.initialize(scope, "CREATE FUNCTION reject_scheduled_job() RETURNS trigger LANGUAGE plpgsql AS 'BEGIN RAISE EXCEPTION ''test-only failure''; END'; CREATE TRIGGER reject_scheduled_job BEFORE INSERT ON _dever_job FOR EACH ROW EXECUTE FUNCTION reject_scheduled_job();").await.unwrap();
|
|
let entry = job::Schedule {
|
|
binding: 0,
|
|
target: "demo.account.hourly",
|
|
schema: "zero",
|
|
cron: "* * * * *",
|
|
policy: Policy {
|
|
retries: 1,
|
|
timeout_ms: 50,
|
|
},
|
|
};
|
|
assert!(
|
|
job::tick(&mut executor, scope, &entry, None, NOW)
|
|
.await
|
|
.is_err()
|
|
);
|
|
assert_eq!(
|
|
case.count(scope, "SELECT COUNT(*) FROM _dever_job_schedule")
|
|
.await,
|
|
0
|
|
);
|
|
assert_eq!(
|
|
case.count(scope, "SELECT COUNT(*) FROM _dever_job_occurrence")
|
|
.await,
|
|
0
|
|
);
|
|
executor
|
|
.initialize(scope, "DROP TRIGGER reject_scheduled_job ON _dever_job")
|
|
.await
|
|
.unwrap();
|
|
assert_eq!(
|
|
job::tick(&mut executor, scope, &entry, None, NOW)
|
|
.await
|
|
.unwrap(),
|
|
1
|
|
);
|
|
});
|
|
}
|