Review fixes: - Keep stored message history beyond the 200-message window; stop messages leaking between radios; reset link/session state on disconnect - Accept firmware's 176-byte RX frames over USB/TCP - Hold APP_START during contact sync; contact-sync watchdog; replay DMs from not-yet-known senders; tombstone late command replies; finish channel sync on ERR_NOT_FOUND; fail region-scoped sends cleanly - DM retry watchdog when RESP_CODE_SENT never arrives; late repeater CLI replies; ACK hash collisions; UTF-8-safe name truncation - Image pipeline: delete-during-decode, lifecycle cancels, decoder memory release, entry cap, dead worker recovery, atomic model writes - Storage: deterministic reaction hash across web/native, Smaz double-decode, per-entry parsing, per-radio path history and regions, review-mode data isolation - UI: safe channel slot selection, byte-length name limits, double-send guard, mounted checks, localized hardcoded strings - Skip persisted-store reload on repeat SELF_INFO Features: - Radio default flood scope (firmware ver 11+) and explicit unscoped sends (ver 12+) - Scan for nearby nodes (#570) - Optional distinct first-hop repeater counting for channel resend (#589) - Optional region next to hop count (#580) Issues: - Message text follows system font size (#569) - Repeater/room password field accepts 20 chars (#576) - TCP auto-reconnect and keepalive (#571) - Order feeds by local receive time; flag future timestamps (#584) - Coding rate help text (#568), French "Favoris" (#575) - iOS/macOS app badge now clears Translations for all new strings in every locale.
96 lines
2.9 KiB
Dart
96 lines
2.9 KiB
Dart
import 'dart:typed_data';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:meshcore_open/models/contact.dart';
|
|
import 'package:meshcore_open/models/message.dart';
|
|
import 'package:meshcore_open/services/message_retry_service.dart';
|
|
|
|
Contact _contact() => Contact(
|
|
publicKey: Uint8List.fromList(List<int>.generate(32, (i) => 0xAA + i)),
|
|
name: 'Test',
|
|
type: 1,
|
|
pathLength: -1,
|
|
path: Uint8List(0),
|
|
lastSeen: DateTime.now(),
|
|
);
|
|
|
|
void main() {
|
|
late MessageRetryService service;
|
|
late Map<String, Message> latest;
|
|
late List<({int attempt, int timestamp})> sends;
|
|
late int timeoutMs;
|
|
final selfKey = Uint8List(32);
|
|
|
|
setUp(() {
|
|
service = MessageRetryService(
|
|
sentWatchdogGrace: const Duration(milliseconds: 10),
|
|
);
|
|
latest = {};
|
|
sends = [];
|
|
timeoutMs = 20;
|
|
service.initialize(
|
|
RetryServiceConfig(
|
|
sendMessage: (_, _, attempt, timestamp) async {
|
|
sends.add((attempt: attempt, timestamp: timestamp));
|
|
},
|
|
addMessage: (_, m) => latest[m.messageId] = m,
|
|
updateMessage: (m) => latest[m.messageId] = m,
|
|
getSelfPublicKey: () => selfKey,
|
|
calculateTimeout: (_, _, {String? contactKey, int? deviceTimeoutMs}) =>
|
|
timeoutMs,
|
|
),
|
|
);
|
|
});
|
|
|
|
tearDown(() => service.dispose());
|
|
|
|
int ackHashFor(int attempt) => MessageRetryService.computeExpectedAckHash(
|
|
sends.first.timestamp,
|
|
attempt,
|
|
'hello',
|
|
selfKey,
|
|
);
|
|
|
|
test('missing RESP_CODE_SENT times out and retries', () async {
|
|
await service.sendMessageWithRetry(contact: _contact(), text: 'hello');
|
|
await pumpEventQueue();
|
|
expect(sends.map((s) => s.attempt), [0]);
|
|
|
|
// Watchdog (20ms + 10ms grace) fires, then the 1s retry backoff.
|
|
await Future<void>.delayed(const Duration(milliseconds: 1200));
|
|
|
|
expect(sends.map((s) => s.attempt), [0, 1]);
|
|
});
|
|
|
|
test('RESP_CODE_SENT replaces the watchdog without a double retry', () async {
|
|
await service.sendMessageWithRetry(contact: _contact(), text: 'hello');
|
|
await pumpEventQueue();
|
|
|
|
timeoutMs = 60000;
|
|
expect(service.updateMessageFromSent(ackHashFor(0), 0), isTrue);
|
|
|
|
await Future<void>.delayed(const Duration(milliseconds: 200));
|
|
|
|
expect(sends, hasLength(1));
|
|
expect(latest.values.single.status, MessageStatus.sent);
|
|
});
|
|
|
|
test('late ACK for an attempt whose SENT was lost still delivers', () async {
|
|
await service.sendMessageWithRetry(contact: _contact(), text: 'hello');
|
|
await pumpEventQueue();
|
|
|
|
// Let the watchdog fire; the retry is now waiting on its backoff.
|
|
await Future<void>.delayed(const Duration(milliseconds: 100));
|
|
expect(latest.values.single.retryCount, 1);
|
|
|
|
service.handleAckReceived(ackHashFor(0), 500);
|
|
|
|
expect(latest.values.single.status, MessageStatus.delivered);
|
|
expect(service.hasPendingMessages, isFalse);
|
|
|
|
// The cancelled backoff must not resend.
|
|
await Future<void>.delayed(const Duration(milliseconds: 1100));
|
|
expect(sends, hasLength(1));
|
|
});
|
|
}
|