Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

refactor: remove action window capacity policy

ldm0d4aced12d7c5
diff --git a/moli-action-window/README.md b/moli-action-window/README.md
index f33d746c4..6147a69c0 100644
--- a/moli-action-window/README.md
+++ b/moli-action-window/README.md
@@ -4,9 +4,13 @@
timer or depending on a renderer.
The first action opens a one-shot window. Its deadline is fixed at
-`first_action_time + window_duration`; later actions join that window without
-moving the deadline. Once a batch is taken, the queue becomes idle and no new
-deadline exists until another action arrives.
+`first_action_time + 1 second`; later actions join that window without moving
+the deadline. Once a batch is taken, the queue becomes idle and no new deadline
+exists until another action arrives.
+
+There is no action-count or memory-capacity cutoff. A window is released only
+by its deadline or an explicit read/synchronization barrier; admitting more
+actions never rejects input or triggers an early batch.
Screenshot, screencast, and other read barriers call `flush` before reading
rendered state. This immediately returns the current batch and cancels its old
@@ -49,13 +53,13 @@ and be admitted in event-loop order.
## Test layers
- Unit tests pin every state transition, deadline edge, compaction rule,
- counter, cancellation, and capacity behavior with a virtual clock.
+ counter, cancellation, and high-volume behavior with a virtual clock.
- Public API tests compile the crate as an external consumer, including owned
scopes, non-`Clone` payloads, consuming batches, all mouse buttons, and
scroll metadata.
- Model tests compare the implementation with an independent flat reference
compactor for all 9,331 mixed sequences up to five actions, plus a
- deterministic 1,000-action capacity stream.
+ deterministic 1,000-action uninterrupted stream.
- End-to-end host tests model Page execution, one observer/render commit per
batch, screenshot and screencast barriers, stale timer wakes, late input,
- capacity rotation, and a real timer armed from `next_deadline`.
+ sustained high-volume input, and a real timer armed from `next_deadline`.
diff --git a/moli-action-window/src/batch.rs b/moli-action-window/src/batch.rs
index ec4633b6e..c7511b155 100644
--- a/moli-action-window/src/batch.rs
+++ b/moli-action-window/src/batch.rs
@@ -35,7 +35,6 @@ impl ActionSequence {
pub enum ActionBatchCause {
Deadline,
Barrier(ActionBarrier),
- Capacity,
}
/// A read or synchronization operation that requires pending actions first.
diff --git a/moli-action-window/src/lib.rs b/moli-action-window/src/lib.rs
index d80b2d1a9..673ef2bbd 100644
--- a/moli-action-window/src/lib.rs
+++ b/moli-action-window/src/lib.rs
@@ -20,10 +20,7 @@ pub use batch::{
ActionBarrier, ActionBatch, ActionBatchCause, ActionBatchId, ActionSequence, PlannedAction,
ScheduledAction, ScrollRun,
};
-pub use window::{
- ActionAdmission, ActionCompaction, ActionWindow, ActionWindowConfig, ActionWindowConfigError,
- AdmissionState,
-};
+pub use window::{ActionAdmission, ActionCompaction, ActionWindow, AdmissionState};
#[cfg(test)]
mod tests;
diff --git a/moli-action-window/src/tests.rs b/moli-action-window/src/tests.rs
index 7fe8b558a..4988d93cb 100644
--- a/moli-action-window/src/tests.rs
+++ b/moli-action-window/src/tests.rs
@@ -1,9 +1,8 @@
use std::time::{Duration, Instant};
use crate::{
- ActionBarrier, ActionBatchCause, ActionCompaction, ActionWindow, ActionWindowConfig,
- ActionWindowConfigError, AdmissionState, ClickAction, InputModifiers, MouseButton,
- PlannedAction, Point, ScrollAction, WindowAction,
+ ActionBarrier, ActionBatchCause, ActionCompaction, ActionWindow, AdmissionState, ClickAction,
+ InputModifiers, MouseButton, PlannedAction, Point, ScrollAction, WindowAction,
};
const SCOPE_A: u8 = 1;
@@ -40,26 +39,13 @@ fn scroll_deltas(action: &PlannedAction<u8, &'static str>) -> Vec<f64> {
}
#[test]
-fn default_config_is_a_one_second_bounded_window() {
- let config = ActionWindowConfig::default();
- assert_eq!(config.duration(), Duration::from_secs(1));
- assert_eq!(config.max_retained_actions(), 4_096);
-}
+fn new_constructor_uses_the_fixed_one_second_window() {
+ let base = Instant::now();
+ let mut window = ActionWindow::<u8, &'static str>::new();
-#[test]
-fn config_rejects_zero_duration() {
- assert_eq!(
- ActionWindowConfig::new(Duration::ZERO, 1),
- Err(ActionWindowConfigError::ZeroDuration)
- );
-}
+ let admission = window.push(SCOPE_A, scroll(1.0), base);
-#[test]
-fn config_rejects_zero_capacity() {
- assert_eq!(
- ActionWindowConfig::new(Duration::from_secs(1), 0),
- Err(ActionWindowConfigError::ZeroCapacity)
- );
+ assert_eq!(admission.deadline(), base + Duration::from_secs(1));
}
#[test]
@@ -397,28 +383,34 @@ fn modifiers_are_a_composable_bit_set() {
}
#[test]
-fn capacity_releases_old_batch_and_starts_new_window() {
+fn large_action_count_stays_in_same_window_until_deadline() {
let base = Instant::now();
- let config = ActionWindowConfig::new(Duration::from_secs(1), 2).expect("valid config");
- let mut window = ActionWindow::<u8, &'static str>::new(config);
- window.push(SCOPE_A, scroll(10.0), base);
- window.push(SCOPE_A, scroll(20.0), at(base, 100));
-
- let admission = window.push(SCOPE_A, scroll(30.0), at(base, 200));
- let ready = admission.ready_batch().expect("capacity batch");
+ let mut window = ActionWindow::<u8, &'static str>::new();
+ for index in 0..10_000 {
+ let admission = window.push(SCOPE_A, scroll(index as f64), base);
+ assert_eq!(
+ admission.state(),
+ if index == 0 {
+ AdmissionState::Opened
+ } else {
+ AdmissionState::Joined
+ }
+ );
+ assert!(admission.ready_batch().is_none());
+ assert_eq!(admission.deadline(), at(base, 1_000));
+ }
- assert_eq!(admission.state(), AdmissionState::Rotated);
- assert_eq!(ready.cause(), ActionBatchCause::Capacity);
- assert_eq!(ready.retained_action_count(), 2);
- assert_eq!(admission.deadline(), at(base, 1_200));
- assert_eq!(window.pending_retained_action_count(), 1);
+ let batch = window.take_due(at(base, 1_000)).expect("deadline batch");
+ assert_eq!(batch.cause(), ActionBatchCause::Deadline);
+ assert_eq!(batch.admitted_action_count(), 10_000);
+ assert_eq!(batch.retained_action_count(), 10_000);
+ assert_eq!(batch.planned_action_count(), 1);
}
#[test]
-fn click_replacement_is_allowed_at_capacity() {
+fn click_replacement_never_rotates_window() {
let base = Instant::now();
- let config = ActionWindowConfig::new(Duration::from_secs(1), 1).expect("valid config");
- let mut window = ActionWindow::<u8, &'static str>::new(config);
+ let mut window = ActionWindow::<u8, &'static str>::new();
window.push(SCOPE_A, click(10.0), base);
let admission = window.push(SCOPE_A, click(20.0), at(base, 100));
@@ -431,10 +423,9 @@ fn click_replacement_is_allowed_at_capacity() {
}
#[test]
-fn deadline_rotation_takes_precedence_over_capacity_rotation() {
+fn deadline_is_the_only_automatic_rotation_cause() {
let base = Instant::now();
- let config = ActionWindowConfig::new(Duration::from_secs(1), 1).expect("valid config");
- let mut window = ActionWindow::<u8, &'static str>::new(config);
+ let mut window = ActionWindow::<u8, &'static str>::new();
window.push(SCOPE_A, scroll(10.0), base);
let admission = window.push(SCOPE_A, scroll(20.0), at(base, 1_000));
diff --git a/moli-action-window/src/window.rs b/moli-action-window/src/window.rs
index 87c0d2df1..b360020ae 100644
--- a/moli-action-window/src/window.rs
+++ b/moli-action-window/src/window.rs
@@ -1,75 +1,11 @@
-use std::{
- error::Error,
- fmt,
- time::{Duration, Instant},
-};
+use std::time::{Duration, Instant};
use crate::{
ActionBarrier, ActionBatch, ActionBatchCause, ActionBatchId, ActionSequence, PlannedAction,
ScheduledAction, ScrollRun, WindowAction,
};
-const DEFAULT_MAX_RETAINED_ACTIONS: usize = 4_096;
-
-#[derive(Clone, Copy, Debug, Eq, PartialEq)]
-pub struct ActionWindowConfig {
- duration: Duration,
- max_retained_actions: usize,
-}
-
-impl ActionWindowConfig {
- pub fn new(
- duration: Duration,
- max_retained_actions: usize,
- ) -> Result<Self, ActionWindowConfigError> {
- if duration.is_zero() {
- return Err(ActionWindowConfigError::ZeroDuration);
- }
- if max_retained_actions == 0 {
- return Err(ActionWindowConfigError::ZeroCapacity);
- }
- Ok(Self {
- duration,
- max_retained_actions,
- })
- }
-
- #[must_use]
- pub const fn duration(self) -> Duration {
- self.duration
- }
-
- #[must_use]
- pub const fn max_retained_actions(self) -> usize {
- self.max_retained_actions
- }
-}
-
-impl Default for ActionWindowConfig {
- fn default() -> Self {
- Self {
- duration: Duration::from_secs(1),
- max_retained_actions: DEFAULT_MAX_RETAINED_ACTIONS,
- }
- }
-}
-
-#[derive(Clone, Copy, Debug, Eq, PartialEq)]
-pub enum ActionWindowConfigError {
- ZeroDuration,
- ZeroCapacity,
-}
-
-impl fmt::Display for ActionWindowConfigError {
- fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
- match self {
- Self::ZeroDuration => formatter.write_str("action window duration must be non-zero"),
- Self::ZeroCapacity => formatter.write_str("action window capacity must be non-zero"),
- }
- }
-}
-
-impl Error for ActionWindowConfigError {}
+const ACTION_WINDOW_DURATION: Duration = Duration::from_secs(1);
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ActionCompaction {
@@ -87,8 +23,8 @@ pub enum AdmissionState {
/// Result of admitting an action.
///
-/// `ready_batch` is present when the previous window reached its deadline or
-/// capacity. The caller must execute it before the newly admitted action.
+/// `ready_batch` is present when the previous window reached its deadline. The
+/// caller must execute it before the newly admitted action.
#[derive(Clone, Debug, PartialEq)]
pub struct ActionAdmission<S, O = ()> {
state: AdmissionState,
@@ -140,19 +76,6 @@ struct PendingWindow<S, O> {
}
impl<S: PartialEq, O> PendingWindow<S, O> {
- fn retained_increment(&self, scope: &S, action: &WindowAction<O>) -> usize {
- match action {
- WindowAction::Click(_) if self.has_click(scope) => 0,
- WindowAction::Scroll(_) | WindowAction::Click(_) | WindowAction::Ordered(_) => 1,
- }
- }
-
- fn has_click(&self, scope: &S) -> bool {
- self.actions.iter().any(|action| {
- matches!(action, PlannedAction::Click { scope: click_scope, .. } if click_scope == scope)
- })
- }
-
fn admit(
&mut self,
scope: S,
@@ -261,9 +184,8 @@ impl<S: PartialEq, O> PendingWindow<S, O> {
}
}
-/// A timer-independent, one-shot action window.
+/// A timer-independent, fixed one-second, one-shot action window.
pub struct ActionWindow<S, O = ()> {
- config: ActionWindowConfig,
next_batch_id: u64,
next_sequence: u64,
open: Option<PendingWindow<S, O>>,
@@ -271,26 +193,20 @@ pub struct ActionWindow<S, O = ()> {
impl<S, O> Default for ActionWindow<S, O> {
fn default() -> Self {
- Self::new(ActionWindowConfig::default())
+ Self::new()
}
}
impl<S, O> ActionWindow<S, O> {
#[must_use]
- pub const fn new(config: ActionWindowConfig) -> Self {
+ pub const fn new() -> Self {
Self {
- config,
next_batch_id: 1,
next_sequence: 1,
open: None,
}
}
- #[must_use]
- pub const fn config(&self) -> ActionWindowConfig {
- self.config
- }
-
#[must_use]
pub const fn is_idle(&self) -> bool {
self.open.is_none()
@@ -337,23 +253,16 @@ impl<S: PartialEq, O> ActionWindow<S, O> {
action: WindowAction<O>,
admitted_at: Instant,
) -> ActionAdmission<S, O> {
- let should_rotate = self.open.as_ref().and_then(|window| {
- if admitted_at >= window.deadline {
- Some(ActionBatchCause::Deadline)
- } else if window.retained_action_count + window.retained_increment(&scope, &action)
- > self.config.max_retained_actions
- {
- Some(ActionBatchCause::Capacity)
- } else {
- None
- }
- });
+ let should_rotate = self
+ .open
+ .as_ref()
+ .is_some_and(|window| admitted_at >= window.deadline);
- let ready_batch = should_rotate.map(|cause| {
+ let ready_batch = should_rotate.then(|| {
self.open
.take()
.expect("rotation requires an open action window")
- .into_batch(admitted_at, cause)
+ .into_batch(admitted_at, ActionBatchCause::Deadline)
});
let state = if ready_batch.is_some() {
@@ -421,7 +330,7 @@ impl<S: PartialEq, O> ActionWindow<S, O> {
fn open_window(&mut self, opened_at: Instant) {
let deadline = opened_at
- .checked_add(self.config.duration)
+ .checked_add(ACTION_WINDOW_DURATION)
.expect("action window deadline exceeds Instant's range");
let id = self.allocate_batch_id();
self.open = Some(PendingWindow {
diff --git a/moli-action-window/tests/end_to_end.rs b/moli-action-window/tests/end_to_end.rs
index 06c37ad40..ac13d280a 100644
--- a/moli-action-window/tests/end_to_end.rs
+++ b/moli-action-window/tests/end_to_end.rs
@@ -1,8 +1,8 @@
use std::{thread, time::Duration, time::Instant};
use moli_action_window::{
- ActionBarrier, ActionBatch, ActionBatchCause, ActionWindow, ActionWindowConfig, ClickAction,
- MouseButton, PlannedAction, Point, ScrollAction, WindowAction,
+ ActionBarrier, ActionBatch, ActionBatchCause, ActionWindow, ClickAction, MouseButton,
+ PlannedAction, Point, ScrollAction, WindowAction,
};
const PAGE: &str = "page-1/document-1";
@@ -209,40 +209,31 @@ fn mixed_actions_preserve_surviving_order_and_apply_observers_once() {
}
#[test]
-fn capacity_batch_executes_before_later_pending_actions() {
+fn sustained_high_volume_stays_in_one_batch_until_deadline() {
let base = Instant::now();
- let config = ActionWindowConfig::new(Duration::from_secs(1), 2).expect("valid config");
- let mut queue = ActionWindow::<&'static str, HostCommand>::new(config);
+ let mut queue = ActionWindow::<&'static str, HostCommand>::new();
let mut page = FakePage::default();
- queue.push(PAGE, scroll(10.0), base);
- queue.push(PAGE, scroll(20.0), at(base, 100));
-
+ for _ in 0..5_000 {
+ let admission = queue.push(PAGE, scroll(1.0), base);
+ assert!(admission.ready_batch().is_none());
+ }
let admission = queue.push(
PAGE,
- WindowAction::Ordered(HostCommand::Marker("after-capacity")),
- at(base, 200),
+ WindowAction::Ordered(HostCommand::Marker("after-scrolls")),
+ at(base, 999),
);
- page.apply(
- admission
- .into_ready_batch()
- .expect("capacity must release first batch"),
- );
- assert_eq!(page.scroll_offset, 30.0);
- assert_eq!(page.render_commits, 1);
+ assert!(admission.ready_batch().is_none());
+ assert_eq!(queue.next_deadline(), Some(at(base, 1_000)));
+ assert_eq!(page.render_commits, 0);
assert!(page.ordered_log.is_empty());
- let frame = page.capture(&mut queue, ActionBarrier::Screenshot, at(base, 300));
+ page.apply(queue.take_due(at(base, 1_000)).expect("deadline batch"));
- assert_eq!(page.ordered_log, vec![("after-capacity", 30.0)]);
- assert_eq!(page.render_commits, 2);
- assert_eq!(frame.render_commit, 2);
- assert_eq!(
- page.applied_causes,
- vec![
- ActionBatchCause::Capacity,
- ActionBatchCause::Barrier(ActionBarrier::Screenshot)
- ]
- );
+ assert_eq!(page.scroll_offset, 100.0);
+ assert_eq!(page.ordered_log, vec![("after-scrolls", 100.0)]);
+ assert_eq!(page.observer_samples, vec![100.0]);
+ assert_eq!(page.render_commits, 1);
+ assert_eq!(page.applied_causes, vec![ActionBatchCause::Deadline]);
}
#[test]
@@ -270,8 +261,7 @@ fn late_input_returns_due_batch_before_opening_new_window() {
#[test]
fn real_timer_driver_uses_public_deadline_and_releases_one_batch() {
- let config = ActionWindowConfig::new(Duration::from_millis(20), 16).expect("valid config");
- let mut queue = ActionWindow::<&'static str, HostCommand>::new(config);
+ let mut queue = ActionWindow::<&'static str, HostCommand>::new();
let mut page = FakePage::default();
let started_at = Instant::now();
queue.push(PAGE, scroll(4.0), started_at);
diff --git a/moli-action-window/tests/model_based.rs b/moli-action-window/tests/model_based.rs
index 000743340..51f96898e 100644
--- a/moli-action-window/tests/model_based.rs
+++ b/moli-action-window/tests/model_based.rs
@@ -1,8 +1,8 @@
use std::time::{Duration, Instant};
use moli_action_window::{
- ActionBarrier, ActionBatch, ActionBatchCause, ActionWindow, ActionWindowConfig, ClickAction,
- MouseButton, PlannedAction, Point, ScrollAction, WindowAction,
+ ActionBarrier, ActionBatch, ActionBatchCause, ActionWindow, ClickAction, MouseButton,
+ PlannedAction, Point, ScrollAction, WindowAction,
};
#[derive(Clone, Debug, PartialEq)]
@@ -198,14 +198,10 @@ fn exhaustive_sequences_up_to_five_actions_match_reference_compactor() {
}
#[test]
-fn capacity_rotation_matches_independent_reference_across_long_mixed_stream() {
+fn long_mixed_stream_never_rotates_before_deadline_and_matches_reference() {
let base = Instant::now();
- let capacity = 7;
- let config = ActionWindowConfig::new(Duration::from_secs(60), capacity).expect("valid config");
- let mut window = ActionWindow::<u8, u64>::new(config);
+ let mut window = ActionWindow::<u8, u64>::new();
let mut reference = Vec::new();
- let mut admitted_in_window = 0;
- let mut emitted_batches = 0;
let mut random = 0x4d59_5df4_d0f3_3173_u64;
for index in 0..1_000_u64 {
@@ -215,27 +211,10 @@ fn capacity_rotation_matches_independent_reference_across_long_mixed_stream() {
let choice = CHOICES[(random as usize) % CHOICES.len()];
let marker = index + 1;
let (scope, action, kind) = action_for(choice, marker);
- let replaces_click = matches!(kind, FlatKind::Click(_))
- && reference.iter().any(|existing: &FlatAction| {
- existing.scope == scope && matches!(existing.kind, FlatKind::Click(_))
- });
- let should_rotate = reference.len() + usize::from(!replaces_click) > capacity;
let admission = window.push(scope, action, base + Duration::from_micros(index));
-
- if should_rotate {
- let ready = admission
- .ready_batch()
- .expect("reference capacity rotation must produce a batch");
- assert_eq!(ready.cause(), ActionBatchCause::Capacity);
- assert_matches_reference(ready, &reference, admitted_in_window);
- assert!(ready.retained_action_count() <= capacity);
- reference.clear();
- admitted_in_window = 0;
- emitted_batches += 1;
- } else {
- assert!(admission.ready_batch().is_none());
- }
+ assert!(admission.ready_batch().is_none());
+ assert_eq!(admission.deadline(), base + Duration::from_secs(1));
reference_admit(
&mut reference,
@@ -245,21 +224,23 @@ fn capacity_rotation_matches_independent_reference_across_long_mixed_stream() {
kind,
},
);
- admitted_in_window += 1;
}
+ assert!(window.take_due(base + Duration::from_millis(999)).is_none());
let final_batch = window
- .flush(ActionBarrier::Explicit, base + Duration::from_secs(1))
+ .flush(ActionBarrier::Explicit, base + Duration::from_millis(999))
.expect("stream should leave a final batch");
- assert_matches_reference(&final_batch, &reference, admitted_in_window);
- assert!(emitted_batches > 100, "stream must exercise many rotations");
+ assert_eq!(
+ final_batch.cause(),
+ ActionBatchCause::Barrier(ActionBarrier::Explicit)
+ );
+ assert_matches_reference(&final_batch, &reference, 1_000);
}
#[test]
-fn every_retained_sequence_is_globally_unique_across_deadline_barrier_and_capacity_batches() {
+fn every_retained_sequence_is_globally_unique_across_deadline_and_barrier_batches() {
let base = Instant::now();
- let config = ActionWindowConfig::new(Duration::from_millis(10), 3).expect("valid config");
- let mut window = ActionWindow::<u8, u64>::new(config);
+ let mut window = ActionWindow::<u8, u64>::new();
let mut emitted_sequences = Vec::new();
let mut causes = Vec::new();
@@ -273,23 +254,15 @@ fn every_retained_sequence_is_globally_unique_across_deadline_barrier_and_capaci
assert!(admission.ready_batch().is_none());
}
- // The fourth retained action crosses capacity before the deadline.
+ // Additional retained actions remain in the same fixed window.
let (scope, action, _) = action_for(Choice::Scroll(1), 4);
- let capacity_batch = window
- .push(scope, action, base + Duration::from_millis(4))
- .into_ready_batch()
- .expect("fourth action must rotate the capacity-three window");
- causes.push(capacity_batch.cause());
- emitted_sequences.extend(
- flatten(&capacity_batch)
- .into_iter()
- .map(|action| action.sequence),
- );
+ let admission = window.push(scope, action, base + Duration::from_millis(4));
+ assert!(admission.ready_batch().is_none());
- // This action arrives after the replacement window's fixed 14ms deadline.
+ // This action arrives at the original window's fixed 1001ms deadline.
let (scope, action, _) = action_for(Choice::Click(0), 5);
let deadline_batch = window
- .push(scope, action, base + Duration::from_millis(15))
+ .push(scope, action, base + Duration::from_millis(1_001))
.into_ready_batch()
.expect("late action must rotate the deadline batch");
causes.push(deadline_batch.cause());
@@ -300,9 +273,12 @@ fn every_retained_sequence_is_globally_unique_across_deadline_barrier_and_capaci
);
let (scope, action, _) = action_for(Choice::Ordered(0), 6);
- window.push(scope, action, base + Duration::from_millis(16));
+ window.push(scope, action, base + Duration::from_millis(1_002));
let barrier_batch = window
- .flush(ActionBarrier::Screenshot, base + Duration::from_millis(17))
+ .flush(
+ ActionBarrier::Screenshot,
+ base + Duration::from_millis(1_003),
+ )
.expect("barrier must release final window");
causes.push(barrier_batch.cause());
emitted_sequences.extend(
@@ -319,7 +295,6 @@ fn every_retained_sequence_is_globally_unique_across_deadline_barrier_and_capaci
assert_eq!(
causes,
vec![
- ActionBatchCause::Capacity,
ActionBatchCause::Deadline,
ActionBatchCause::Barrier(ActionBarrier::Screenshot),
]
diff --git a/moli-action-window/tests/public_api.rs b/moli-action-window/tests/public_api.rs
index 64cf3f0ea..d21703b1b 100644
--- a/moli-action-window/tests/public_api.rs
+++ b/moli-action-window/tests/public_api.rs
@@ -1,38 +1,23 @@
use std::time::{Duration, Instant};
use moli_action_window::{
- ActionBarrier, ActionBatchCause, ActionCompaction, ActionWindow, ActionWindowConfig,
- ActionWindowConfigError, AdmissionState, ClickAction, InputModifiers, MouseButton,
- PlannedAction, Point, ScrollAction, ScrollDeltaMode, WindowAction,
+ ActionBarrier, ActionBatchCause, ActionCompaction, ActionWindow, AdmissionState, ClickAction,
+ InputModifiers, MouseButton, PlannedAction, Point, ScrollAction, ScrollDeltaMode, WindowAction,
};
#[test]
fn default_public_surface_starts_idle_with_one_second_policy() {
- let window = ActionWindow::<String>::default();
+ let base = Instant::now();
+ let mut window = ActionWindow::<String>::default();
assert!(window.is_idle());
assert_eq!(window.next_deadline(), None);
- assert_eq!(window.config().duration(), Duration::from_secs(1));
- assert_eq!(window.config().max_retained_actions(), 4_096);
-}
-
-#[test]
-fn invalid_config_errors_are_stable_and_actionable() {
- let zero_duration =
- ActionWindowConfig::new(Duration::ZERO, 1).expect_err("zero duration must be rejected");
- let zero_capacity = ActionWindowConfig::new(Duration::from_secs(1), 0)
- .expect_err("zero capacity must be rejected");
-
- assert_eq!(zero_duration, ActionWindowConfigError::ZeroDuration);
- assert_eq!(
- zero_duration.to_string(),
- "action window duration must be non-zero"
- );
- assert_eq!(zero_capacity, ActionWindowConfigError::ZeroCapacity);
- assert_eq!(
- zero_capacity.to_string(),
- "action window capacity must be non-zero"
+ let admission = window.push(
+ "document".to_owned(),
+ WindowAction::Scroll(ScrollAction::pixels(Point::default(), 0.0, 1.0)),
+ base,
);
+ assert_eq!(admission.deadline(), base + Duration::from_secs(1));
}
#[test]
@@ -62,25 +47,24 @@ fn public_api_accepts_owned_scope_and_non_clone_ordered_payload() {
}
#[test]
-fn admission_can_be_consumed_to_execute_capacity_batch() {
+fn late_admission_can_be_consumed_to_execute_deadline_batch() {
let base = Instant::now();
- let config = ActionWindowConfig::new(Duration::from_secs(1), 1).expect("valid config");
- let mut window = ActionWindow::<u8, &'static str>::new(config);
+ let mut window = ActionWindow::<u8, &'static str>::new();
window.push(1, WindowAction::Ordered("first"), base);
let admission = window.push(
1,
WindowAction::Ordered("second"),
- base + Duration::from_millis(10),
+ base + Duration::from_secs(1),
);
assert_eq!(admission.state(), AdmissionState::Rotated);
assert_eq!(admission.batch_id().get(), 2);
let ready = admission
.into_ready_batch()
- .expect("capacity rotation must return the first batch");
+ .expect("deadline rotation must return the first batch");
assert_eq!(ready.id().get(), 1);
- assert_eq!(ready.cause(), ActionBatchCause::Capacity);
+ assert_eq!(ready.cause(), ActionBatchCause::Deadline);
assert_eq!(ready.admitted_action_count(), 1);
assert_eq!(ready.retained_action_count(), 1);
}
@@ -167,10 +151,9 @@ fn canceling_unknown_scope_is_a_noop_and_preserves_deadline() {
}
#[test]
-fn click_replacement_reports_public_compaction_without_capacity_rotation() {
+fn click_replacement_reports_public_compaction_without_rotation() {
let base = Instant::now();
- let config = ActionWindowConfig::new(Duration::from_secs(1), 1).expect("valid config");
- let mut window = ActionWindow::<u8, ()>::new(config);
+ let mut window = ActionWindow::<u8, ()>::new();
window.push(
1,
WindowAction::Click(ClickAction::new(Point::new(1.0, 1.0), MouseButton::Left, 1)),