36 lines
1.2 KiB
Dart
36 lines
1.2 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:marianum_mobile/utils/exponential_backoff.dart';
|
|
|
|
void main() {
|
|
group('exponentialBackoff', () {
|
|
test('doubles per attempt starting at base', () {
|
|
expect(exponentialBackoff(1), const Duration(milliseconds: 500));
|
|
expect(exponentialBackoff(2), const Duration(seconds: 1));
|
|
expect(exponentialBackoff(3), const Duration(seconds: 2));
|
|
expect(exponentialBackoff(4), const Duration(seconds: 4));
|
|
});
|
|
|
|
test('caps at max', () {
|
|
expect(exponentialBackoff(5), const Duration(seconds: 5));
|
|
expect(exponentialBackoff(40), const Duration(seconds: 5));
|
|
expect(exponentialBackoff(1000), const Duration(seconds: 5));
|
|
});
|
|
|
|
test('treats attempt 0 and negatives like the first attempt', () {
|
|
expect(exponentialBackoff(0), const Duration(milliseconds: 500));
|
|
expect(exponentialBackoff(-3), const Duration(milliseconds: 500));
|
|
});
|
|
|
|
test('honours custom base and max', () {
|
|
expect(
|
|
exponentialBackoff(
|
|
3,
|
|
base: const Duration(seconds: 1),
|
|
max: const Duration(seconds: 3),
|
|
),
|
|
const Duration(seconds: 3),
|
|
);
|
|
});
|
|
});
|
|
}
|