Add failure backoff for sync auto triggers
This commit is contained in:
@@ -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>();
|
||||
|
||||
Reference in New Issue
Block a user