дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 18:17:15 +02:00
events.schedule(id, after-ms) wakes the plugin once with a timer event in the window of the call that set it; the same id replaces it, so retries and backoff stay the plugin's own, and events.cancel-schedule drops it. 250 ms to 24 h, at most 16 pending, no capability. Timers activate an idle plugin, survive idle reclaim and end with the window, its project or the plugin. SDK: host::schedule, host::cancel_schedule, Event::Timer, MockHost timers. Components rebuilt. Closes #8195
34 рядки
1.4 KiB
Rust
34 рядки
1.4 KiB
Rust
use openidea_plugin::{Error, Event, host, mock::MockHost};
|
|
|
|
#[test]
|
|
fn schedule_replaces_cancels_and_fires_once() {
|
|
let mock = MockHost::install();
|
|
// No capability: a plugin only wakes itself.
|
|
host::schedule("retry", 2_000).unwrap();
|
|
host::schedule("poll", 250).unwrap();
|
|
// The same id again replaces it: the plugin paces its own backoff.
|
|
host::schedule("retry", 4_000).unwrap();
|
|
assert_eq!(mock.timers(), [("poll".to_owned(), 250), ("retry".to_owned(), 4_000)].into());
|
|
|
|
host::cancel_schedule("poll");
|
|
host::cancel_schedule("unknown");
|
|
assert_eq!(mock.timers().len(), 1);
|
|
assert_eq!(mock.fire_timer("retry"), Some(Event::Timer("retry".into())));
|
|
assert_eq!(mock.fire_timer("retry"), None, "a timer fires once");
|
|
assert_eq!(Event::from_other("timer".into(), "\"retry\"".into()), Event::Timer("retry".into()));
|
|
}
|
|
|
|
#[test]
|
|
fn schedule_bounds() {
|
|
let mock = MockHost::install();
|
|
for (id, after) in [("", 1_000), ("a\nb", 1_000), (&*"x".repeat(129), 1_000), ("ok", 249), ("ok", 86_400_001)] {
|
|
assert!(matches!(host::schedule(id, after), Err(Error::Invalid(_))), "{id:?} {after}");
|
|
}
|
|
for i in 0..16 {
|
|
host::schedule(&format!("t{i}"), 1_000).unwrap();
|
|
}
|
|
assert!(matches!(host::schedule("t16", 1_000), Err(Error::Invalid(_))));
|
|
host::schedule("t0", 86_400_000).unwrap();
|
|
assert_eq!(mock.timers().len(), 16);
|
|
}
|