|
1 | 1 | //! Deterministic helpers for supervisor tests. |
2 | 2 | //! |
3 | 3 | //! The module provides small reusable fixtures for event collection, paused |
4 | | -//! time, fake task outcomes, and deterministic jitter. |
| 4 | +//! time, and deterministic jitter. |
5 | 5 |
|
6 | | -use crate::error::types::TaskFailure; |
7 | 6 | use crate::event::payload::{SupervisorEvent, What, Where}; |
8 | 7 | use crate::event::time::{CorrelationId, EventSequence, EventSequenceSource, EventTime, When}; |
9 | 8 | use crate::id::types::{Attempt, ChildId, Generation, SupervisorPath}; |
@@ -113,79 +112,6 @@ impl DeterministicJitter { |
113 | 112 | } |
114 | 113 | } |
115 | 114 |
|
116 | | -/// Fake task outcome for tests that do not need a real runtime. |
117 | | -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] |
118 | | -pub enum FakeTaskOutcome { |
119 | | - /// Task completes successfully. |
120 | | - Complete, |
121 | | - /// Task is cancelled. |
122 | | - Cancel, |
123 | | - /// Task returns a typed failure. |
124 | | - Fail { |
125 | | - /// Failure payload returned by the task. |
126 | | - failure: TaskFailure, |
127 | | - }, |
128 | | -} |
129 | | - |
130 | | -/// Fake task factory that returns deterministic outcomes in order. |
131 | | -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] |
132 | | -pub struct FakeTaskFactory { |
133 | | - /// Ordered outcomes returned by attempts. |
134 | | - pub outcomes: Vec<FakeTaskOutcome>, |
135 | | - /// Next outcome index. |
136 | | - pub next_index: usize, |
137 | | -} |
138 | | - |
139 | | -impl FakeTaskFactory { |
140 | | - /// Creates a fake task factory. |
141 | | - /// |
142 | | - /// # Arguments |
143 | | - /// |
144 | | - /// - `outcomes`: Ordered outcomes returned by attempts. |
145 | | - /// |
146 | | - /// # Returns |
147 | | - /// |
148 | | - /// Returns a [`FakeTaskFactory`]. |
149 | | - /// |
150 | | - /// # Examples |
151 | | - /// |
152 | | - /// ``` |
153 | | - /// let mut factory = rust_supervisor::test_support::factory::FakeTaskFactory::new(vec![ |
154 | | - /// rust_supervisor::test_support::factory::FakeTaskOutcome::Complete, |
155 | | - /// ]); |
156 | | - /// assert!(matches!( |
157 | | - /// factory.next_outcome(), |
158 | | - /// rust_supervisor::test_support::factory::FakeTaskOutcome::Complete |
159 | | - /// )); |
160 | | - /// ``` |
161 | | - pub fn new(outcomes: Vec<FakeTaskOutcome>) -> Self { |
162 | | - Self { |
163 | | - outcomes, |
164 | | - next_index: 0, |
165 | | - } |
166 | | - } |
167 | | - |
168 | | - /// Returns the next deterministic outcome. |
169 | | - /// |
170 | | - /// # Arguments |
171 | | - /// |
172 | | - /// This function has no arguments. |
173 | | - /// |
174 | | - /// # Returns |
175 | | - /// |
176 | | - /// Returns the next [`FakeTaskOutcome`], or `Complete` after configured |
177 | | - /// outcomes are exhausted. |
178 | | - pub fn next_outcome(&mut self) -> FakeTaskOutcome { |
179 | | - let outcome = self |
180 | | - .outcomes |
181 | | - .get(self.next_index) |
182 | | - .cloned() |
183 | | - .unwrap_or(FakeTaskOutcome::Complete); |
184 | | - self.next_index = self.next_index.saturating_add(1); |
185 | | - outcome |
186 | | - } |
187 | | -} |
188 | | - |
189 | 115 | /// Collector that stores supervisor events in memory. |
190 | 116 | #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)] |
191 | 117 | pub struct EventCollector { |
|
0 commit comments