Flush accepted tab moves before replacement restoration
This commit is contained in:
@@ -261,7 +261,7 @@ void main() {
|
||||
},
|
||||
);
|
||||
test(
|
||||
'disposed queued writes cannot overwrite a replacement controller',
|
||||
'accepted old writes finish before a replacement load and newer move',
|
||||
() async {
|
||||
final gate = Completer<bool>();
|
||||
final store = MemoryTabLocationsStore()..write = gate;
|
||||
@@ -288,10 +288,12 @@ void main() {
|
||||
expect(store.value.routes[AppDestination.pipelines], AppRoute.settings);
|
||||
expect(
|
||||
store.value.routes[AppDestination.chat],
|
||||
isNull,
|
||||
reason: 'the disposed owner never starts its queued Chat write',
|
||||
AppRoute.chat,
|
||||
reason: 'the accepted queued Chat move is durable before replacement',
|
||||
);
|
||||
expect(store.writes, hasLength(2));
|
||||
expect(store.writes, hasLength(3));
|
||||
expect(store.writes[1].active, AppDestination.chat);
|
||||
expect(store.writes.last.active, AppDestination.runs);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -322,7 +324,46 @@ void main() {
|
||||
expect(saved.active, AppDestination.runs);
|
||||
expect(saved.routes[AppDestination.runs], AppRoute.run(18));
|
||||
expect(saved.routes[AppDestination.pipelines], AppRoute.settings);
|
||||
expect(saved.routes[AppDestination.chat], isNull);
|
||||
expect(saved.routes[AppDestination.chat], AppRoute.chat);
|
||||
},
|
||||
);
|
||||
test(
|
||||
'recreating without a new choice restores the last accepted queued move',
|
||||
() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
final oldStore = GatedPreferencesTabLocationsStore(
|
||||
scope: 'ordinary-restart',
|
||||
);
|
||||
final old = TabLocations(oldStore)..record(AppRoute.settings);
|
||||
await old.restore(restoreActive: false);
|
||||
await oldStore.started.future;
|
||||
old.record(AppRoute.chatSession('last-open-chat'));
|
||||
old.dispose();
|
||||
old.record(AppRoute.run(999)); // disposal rejects new, unaccepted moves
|
||||
const newStore = SharedPreferencesTabLocationsStore(
|
||||
scope: 'ordinary-restart',
|
||||
);
|
||||
final replacement = TabLocations(newStore)
|
||||
..record(AppRoute.pipelines, visited: false);
|
||||
var readFinished = false;
|
||||
final restoring = replacement.restore(restoreActive: true).then((value) {
|
||||
readFinished = true;
|
||||
return value;
|
||||
});
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
expect(readFinished, isFalse);
|
||||
oldStore.gate.complete();
|
||||
expect(await restoring, AppRoute.chatSession('last-open-chat'));
|
||||
await old.settled;
|
||||
await replacement.settled;
|
||||
final saved = await newStore.load();
|
||||
expect(saved.active, AppDestination.chat);
|
||||
expect(
|
||||
saved.routes[AppDestination.chat],
|
||||
AppRoute.chatSession('last-open-chat'),
|
||||
);
|
||||
expect(saved.routes[AppDestination.runs], isNull);
|
||||
expect(saved.routes[AppDestination.pipelines], AppRoute.settings);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user