Stamp legacy images inside the migration; hold early channel frames
- Image entries are stamped with their channel ID before the migration is marked done, so an interrupted run repeats it instead of leaving them unstamped (and invisible) forever. - Channel message/data frames that arrive before this session's slot map is confirmed are held and replayed once it is. Current firmware only sends them in reply to SYNC_NEXT_MESSAGE, which already waits; this guards against a stale saved map filing them under the wrong channel.
This commit is contained in:
1 parent
679116ed03
commit
6a8df764bb
4 files changed
+87
-5
No files matched your search
@@ -243,6 +243,32 @@ void main() {
|
||||
expect(_storedTexts(hikingId), isEmpty);
|
||||
});
|
||||
|
||||
test('a channel frame that arrives before the slot map is held, then filed '
|
||||
'by the confirmed map', () async {
|
||||
final radio = _TestRadio(
|
||||
afterHandle: (radio, frame) {
|
||||
if (frame[0] == cmdAppStart) {
|
||||
radio.emitForTest(
|
||||
ReviewFrames.channelMessage(
|
||||
channelIndex: 1,
|
||||
sender: 'Sam',
|
||||
message: 'before the map',
|
||||
timestampSecs: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
await _connect(
|
||||
radio,
|
||||
// A stale map from last session would file it under the ghost channel.
|
||||
seed: () => _seedSlotMap({0: _id(_psk(0)), 1: ghostId, 2: _id(_psk(2))}),
|
||||
);
|
||||
await _waitFor(() => _texts(1).contains('before the map'));
|
||||
expect(_storedTexts(hikingId), contains('before the map'));
|
||||
expect(_storedTexts(ghostId), isNot(contains('before the map')));
|
||||
});
|
||||
|
||||
test('MSG_WAITING before the channel sync waits for the slot map', () async {
|
||||
// DEVICE_INFO is held back so MSG_WAITING lands between SELF_INFO and the
|
||||
// start of the channel sync.
|
||||
|
||||
@@ -254,6 +254,27 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test('images are stamped before the migration is marked done', () async {
|
||||
await _init(legacyValues());
|
||||
await expectLater(
|
||||
ChannelStorageMigration.migrate(
|
||||
_scopeA,
|
||||
beforeDone: (_) async => throw StateError('killed'),
|
||||
),
|
||||
throwsStateError,
|
||||
);
|
||||
// Not marked done, so the next launch stamps again.
|
||||
Map<int, String>? stamped;
|
||||
await ChannelStorageMigration.migrate(
|
||||
_scopeA,
|
||||
beforeDone: (slotIds) async => stamped = slotIds,
|
||||
);
|
||||
expect(stamped, {0: _idOne, 2: _idTwo});
|
||||
// Data moved by the first run is still there.
|
||||
final messages = ChannelMessageStore()..setPublicKeyHex = _deviceA;
|
||||
expect((await messages.loadChannelMessages(_idOne)).single.text, 'hello');
|
||||
});
|
||||
|
||||
test('skips a scope that must not adopt legacy data', () async {
|
||||
await _init(legacyValues());
|
||||
scopesWithoutLegacyMigration.add(_scopeA);
|
||||
|
||||
Reference in new issue
Block a user