fix(test): cancel one-shot Timers on CacheFiller / MutationReplayer dispose
Smoke test failed: "A Timer is still pending even after the widget tree was disposed." Both workers fired their initial-delay Timer via `Timer(duration, _sweep)` and stored only the periodic ticker in the cancellable field — the one-shot Timer leaked past dispose and tripped the test framework's invariant check. Track both as _initialTimer + _intervalTimer; cancel both in dispose(). Behavior is unchanged in production (ref.onDispose only fires on process death normally); this is purely a test-harness fix.
This commit is contained in:
+6
-4
@@ -37,7 +37,8 @@ class CacheFiller {
|
||||
CacheFiller(this._ref);
|
||||
final Ref _ref;
|
||||
|
||||
Timer? _timer;
|
||||
Timer? _initialTimer;
|
||||
Timer? _intervalTimer;
|
||||
bool _running = false;
|
||||
bool _disposed = false;
|
||||
|
||||
@@ -61,8 +62,8 @@ class CacheFiller {
|
||||
static const _maxIdsPerSweep = 200;
|
||||
|
||||
void start() {
|
||||
Timer(_initialDelay, _sweep);
|
||||
_timer = Timer.periodic(_interval, (_) => _sweep());
|
||||
_initialTimer = Timer(_initialDelay, _sweep);
|
||||
_intervalTimer = Timer.periodic(_interval, (_) => _sweep());
|
||||
}
|
||||
|
||||
Future<void> _sweep() async {
|
||||
@@ -217,7 +218,8 @@ class CacheFiller {
|
||||
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
_timer?.cancel();
|
||||
_initialTimer?.cancel();
|
||||
_intervalTimer?.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user