fix: preserve queued settings and recover interrupted or corrupt state
This commit is contained in:
@@ -15,6 +15,37 @@ void main() {
|
||||
tearDown(() async {
|
||||
await directory.delete(recursive: true);
|
||||
});
|
||||
for (final badBackup in [false, true]) {
|
||||
test(
|
||||
'fresh recovery archives corrupt primary and ${badBackup ? 'corrupt' : 'missing'} backup before saving',
|
||||
() async {
|
||||
await File('${directory.path}/hepan_snapshot.json')
|
||||
.writeAsString('damaged primary');
|
||||
if (badBackup) {
|
||||
await File('${directory.path}/hepan_snapshot.bak')
|
||||
.writeAsString('damaged backup');
|
||||
}
|
||||
final store = FileSnapshotStore(directory);
|
||||
await expectLater(store.load(), throwsFormatException);
|
||||
await store.startFresh();
|
||||
final archives = await directory
|
||||
.list()
|
||||
.where((e) => e.path.contains('.damaged-'))
|
||||
.toList();
|
||||
expect(archives, hasLength(badBackup ? 2 : 1));
|
||||
final contents = await Future.wait(
|
||||
archives.map((e) => File(e.path).readAsString()),
|
||||
);
|
||||
expect(contents, contains('damaged primary'));
|
||||
if (badBackup) {
|
||||
expect(contents, contains('damaged backup'));
|
||||
}
|
||||
expect((await store.load())!.courses, isEmpty);
|
||||
await store.save(AppSnapshot(courses: [course()]));
|
||||
expect((await store.load())!.courses.single.id, 'math');
|
||||
},
|
||||
);
|
||||
}
|
||||
test(
|
||||
'reopening restores courses, settings and calendar identifiers',
|
||||
() async {
|
||||
|
||||
Reference in New Issue
Block a user