Add failure backoff for sync auto triggers

This commit is contained in:
Rijad Zuzo
2026-02-15 20:23:02 +01:00
parent 5228799abb
commit 831c217e29
3 changed files with 64 additions and 3 deletions
@@ -30,6 +30,29 @@ void main() {
expect(controller.lastTriggeredAt, now);
});
test('applies backoff after failed sync attempts', () async {
DateTime now = DateTime(2026, 2, 15, 14);
bool shouldFail = true;
final SyncAutoTriggerController controller = SyncAutoTriggerController(
syncNow: () async => _result(success: !shouldFail),
now: () => now,
minimumInterval: const Duration(seconds: 60),
);
final bool first = await controller.trigger();
now = now.add(const Duration(seconds: 61));
final bool second = await controller.trigger();
now = now.add(const Duration(seconds: 60));
shouldFail = false;
final bool third = await controller.trigger();
expect(first, isTrue);
expect(second, isFalse);
expect(third, isTrue);
expect(controller.consecutiveFailures, 0);
});
test('does not run a second sync while a run is still in progress', () async {
int callCount = 0;
final Completer<void> completer = Completer<void>();