Initial Dever 0.0.1
This commit is contained in:
commit
81233d098c
1479 files changed
+163782
No files matched your search
@@ -0,0 +1,110 @@
|
||||
use super::*;
|
||||
use dever_runtime::time::cron::Cron;
|
||||
|
||||
#[test]
|
||||
fn utc_cron_validates_ranges_steps_and_calendar_or() {
|
||||
let cron = Cron::parse("*/15 9-17/2 1,15 * 1-5").unwrap();
|
||||
assert!(cron.matches(30, 11, 8, 10, 1));
|
||||
assert!(cron.matches(45, 9, 15, 10, 0));
|
||||
assert!(!cron.matches(45, 9, 8, 10, 0));
|
||||
assert!(!cron.matches(10, 9, 15, 10, 0));
|
||||
for source in [
|
||||
"* * * *",
|
||||
"60 * * * *",
|
||||
"* 24 * * *",
|
||||
"* * 0 * *",
|
||||
"* * * 13 *",
|
||||
"* * * * 7",
|
||||
"*/0 * * * *",
|
||||
"* * * * 5-1",
|
||||
"* * * * -1",
|
||||
] {
|
||||
assert!(Cron::parse(source).is_err(), "{source}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn schedule_cursor_and_completed_occurrences_are_durable() {
|
||||
let directory = Directory::new();
|
||||
let runtime = Runtime::new(Limits::default()).unwrap();
|
||||
runtime
|
||||
.run(async |scope| {
|
||||
let database = Database::open(&directory.0, options(), scope)
|
||||
.await
|
||||
.unwrap();
|
||||
let mut executor = database.executor().await.unwrap();
|
||||
executor
|
||||
.schema(scope, job::schema::TABLE, job::schema::SQL)
|
||||
.await
|
||||
.unwrap();
|
||||
let entry = job::Schedule {
|
||||
binding: 0,
|
||||
target: "demo.account.job.hourly",
|
||||
schema: "zero",
|
||||
cron: "* * * * *",
|
||||
policy: Policy {
|
||||
retries: 1,
|
||||
timeout_ms: 50,
|
||||
},
|
||||
};
|
||||
assert_eq!(
|
||||
job::tick(&mut executor, scope, &entry, None, 600000)
|
||||
.await
|
||||
.unwrap(),
|
||||
1
|
||||
);
|
||||
let claim = job::claim(&mut executor, scope, 600000, 100)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
job::complete(&mut executor, scope, &claim, 600001)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
job::tick(&mut executor, scope, &entry, None, 600020)
|
||||
.await
|
||||
.unwrap(),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
job::tick(&mut executor, scope, &entry, None, 600000 + 60000 * 300)
|
||||
.await
|
||||
.unwrap(),
|
||||
256
|
||||
);
|
||||
assert_eq!(
|
||||
job::tick(&mut executor, scope, &entry, None, 600000 + 60000 * 300)
|
||||
.await
|
||||
.unwrap(),
|
||||
44
|
||||
);
|
||||
assert_eq!(
|
||||
job::tick(&mut executor, scope, &entry, None, 0)
|
||||
.await
|
||||
.unwrap(),
|
||||
0
|
||||
);
|
||||
let changed = job::Schedule {
|
||||
cron: "*/2 * * * *",
|
||||
..entry
|
||||
};
|
||||
assert!(
|
||||
job::tick(&mut executor, scope, &changed, None, 600000)
|
||||
.await
|
||||
.is_err()
|
||||
);
|
||||
drop(executor);
|
||||
drop(database);
|
||||
let database = Database::open(&directory.0, options(), scope)
|
||||
.await
|
||||
.unwrap();
|
||||
let mut executor = database.executor().await.unwrap();
|
||||
assert_eq!(
|
||||
job::tick(&mut executor, scope, &entry, None, 600000 + 60000 * 300)
|
||||
.await
|
||||
.unwrap(),
|
||||
0
|
||||
);
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
Reference in new issue
Block a user