fixed possible lockups on app start
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:marianum_mobile/storage/hydrated_storage_bootstrap.dart';
|
||||
|
||||
void main() {
|
||||
test('InMemoryStorage round-trips, deletes and clears', () async {
|
||||
final storage = InMemoryStorage();
|
||||
expect(storage.read('a'), isNull);
|
||||
|
||||
await storage.write('a', {'x': 1});
|
||||
await storage.write('b', 'two');
|
||||
expect(storage.read('a'), {'x': 1});
|
||||
expect(storage.read('b'), 'two');
|
||||
|
||||
await storage.delete('a');
|
||||
expect(storage.read('a'), isNull);
|
||||
expect(storage.read('b'), 'two');
|
||||
|
||||
await storage.clear();
|
||||
expect(storage.read('b'), isNull);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
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),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user