Commit 5b832fc
test(actor): deflake debounce/derived/liveness timing tests (#665)
Replace fixed-sleep-then-assert with condition-based waiting (wait_for
helper) in debounce.rs, derived.rs, and lib.rs. No production code
changed — all fixes are test-only.
Root cause per test:
debounce_single_message / debounce_separate_bursts
Test race: fixed sleeps (100ms / 80ms) smaller than the timer + actor
message-delivery chain under parallel suite load. Fixed by polling
count.load() with a 2000ms timeout instead of sleeping.
debounce_rapid_messages / throttle_* tests
Same class of race on the positive "eventually happens" assertions.
Hardened proactively. throttle_rate_limited's "still throttled"
assertion keeps a short fixed sleep (20ms << 100ms cooldown) with a
comment explaining why it is a genuine timing invariant.
debounce_timer_reset
The intermediate assert_eq!(count, 0) at 30ms is a real timing
invariant (timer must not have fired) — kept as-is with an explanatory
comment. The final assert_eq!(count, 1) replaced with wait_for.
derived_caches_unchanged
Test race: DerivedActor::started() spawns a task to compute the
initial UpdateCache. If the test's Subscribe(counter) message is
processed by DerivedActor *before* that warm-up UpdateCache arrives,
the actor's cache is still None when UpdateCache(2) arrives later —
triggering a dirty→idle→Notify cycle that increments count to 1
(expected 0).
Fixed by polling two consecutive d.get().await calls until they return
Arc::ptr_eq (both served from self.cached, not fresh computes). Once
ptr_eq holds, self.cached is definitely Some(2), so any subsequent
UpdateCache(2) — including any late warm-up — deduplicates to no-op.
The counter is then subscribed and Set(4) tested.
derived_notifies_on_value_change
Removed redundant 50ms warm-up sleep; uses wait_for for the positive
"subscriber notified" assertion (count >= 1) instead.
ask_dead_actor_returns_closed / send_dead_actor_returns_send_error
/ recipient_dead_actor / system_shutdown_terminates_ctx_spawned_child
Test race: system.shutdown().await returns when done_rx fires (at
end of run_mailbox), but the tokio task hasn't yet dropped the
Receiver<T>, so tx.is_closed() (== is_alive()) can still return
false for a brief window. Fixed by polling !addr.is_alive() with
1ms retries (max 200ms) before asserting channel-closed semantics.
Verification:
- Each of the 3 originally-reported flaky tests: 30/30 green in isolation
- cargo test -p willow-actor --lib: 5/5 consecutive runs, 94/94 tests each
- just check: zero warnings, all tests green
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 94aa11a commit 5b832fc
3 files changed
Lines changed: 276 additions & 33 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
162 | 181 | | |
163 | 182 | | |
164 | 183 | | |
| |||
207 | 226 | | |
208 | 227 | | |
209 | 228 | | |
210 | | - | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
211 | 238 | | |
212 | 239 | | |
213 | 240 | | |
| |||
223 | 250 | | |
224 | 251 | | |
225 | 252 | | |
226 | | - | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
227 | 261 | | |
228 | 262 | | |
229 | 263 | | |
| |||
237 | 271 | | |
238 | 272 | | |
239 | 273 | | |
| 274 | + | |
240 | 275 | | |
241 | 276 | | |
242 | 277 | | |
243 | | - | |
244 | | - | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
245 | 295 | | |
246 | 296 | | |
247 | 297 | | |
| |||
253 | 303 | | |
254 | 304 | | |
255 | 305 | | |
| 306 | + | |
| 307 | + | |
256 | 308 | | |
257 | 309 | | |
258 | | - | |
259 | | - | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
260 | 318 | | |
261 | 319 | | |
262 | | - | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
263 | 326 | | |
264 | 327 | | |
265 | 328 | | |
| |||
272 | 335 | | |
273 | 336 | | |
274 | 337 | | |
275 | | - | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
276 | 347 | | |
277 | 348 | | |
278 | 349 | | |
| |||
286 | 357 | | |
287 | 358 | | |
288 | 359 | | |
289 | | - | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
290 | 369 | | |
291 | 370 | | |
292 | | - | |
293 | 371 | | |
294 | | - | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
295 | 383 | | |
296 | 384 | | |
297 | 385 | | |
| |||
302 | 390 | | |
303 | 391 | | |
304 | 392 | | |
305 | | - | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
306 | 402 | | |
307 | | - | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
308 | 411 | | |
309 | 412 | | |
310 | 413 | | |
| |||
318 | 421 | | |
319 | 422 | | |
320 | 423 | | |
321 | | - | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
322 | 432 | | |
323 | 433 | | |
324 | | - | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
325 | 442 | | |
326 | 443 | | |
327 | 444 | | |
| |||
0 commit comments