Enforce flood threshold in retry and path-prep selection
Ensure MessageRetryService forces flood once the attempt reaches floodFromAttempt even if a selector returns null, and pass SendAttemptPlan.floodFromAttempt from preparePathForContactSend so zero-budget plans keep the saved path.
This commit is contained in:
1 parent
27cc332383
commit
723fa18b68
4 files changed
+308
-13
No files matched your search
@@ -165,4 +165,122 @@ void main() {
|
||||
expect(sends, [0]);
|
||||
expect(latest.last.status, MessageStatus.failed);
|
||||
});
|
||||
|
||||
test(
|
||||
'flood-only rotation floods saved direct contact even if selector returns null',
|
||||
() async {
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.updateSettings(
|
||||
settings.settings.copyWith(
|
||||
autoRouteRotationEnabled: true,
|
||||
directRetries: 0,
|
||||
floodRetries: 1,
|
||||
),
|
||||
);
|
||||
|
||||
final service = MessageRetryService(
|
||||
sentWatchdogGrace: const Duration(milliseconds: 5),
|
||||
);
|
||||
addTearDown(service.dispose);
|
||||
final latest = <Message>[];
|
||||
final sends = <int>[];
|
||||
var clearedCount = 0;
|
||||
var setPathCount = 0;
|
||||
service.initialize(
|
||||
RetryServiceConfig(
|
||||
sendMessage: (_, _, attempt, _) async {
|
||||
sends.add(attempt);
|
||||
},
|
||||
addMessage: (_, message) => latest.add(message),
|
||||
updateMessage: (message) => latest.add(message),
|
||||
clearContactPath: (_) async {
|
||||
clearedCount++;
|
||||
},
|
||||
setContactPath: (_, _, _) async {
|
||||
setPathCount++;
|
||||
},
|
||||
calculateTimeout:
|
||||
(_, _, {String? contactKey, int? deviceTimeoutMs}) => 15,
|
||||
appSettingsService: settings,
|
||||
selectRetryPath: (_, _, _, _) => null,
|
||||
),
|
||||
);
|
||||
|
||||
await service.sendMessageWithRetry(
|
||||
contact: _contact(pathLength: 1, path: const [0x11]),
|
||||
text: 'hello',
|
||||
);
|
||||
await pumpEventQueue();
|
||||
await Future<void>.delayed(const Duration(milliseconds: 200));
|
||||
|
||||
expect(sends, [0]);
|
||||
expect(clearedCount, 1);
|
||||
expect(setPathCount, 0);
|
||||
expect(latest.last.pathLength, -1);
|
||||
expect(latest.last.pathBytes, isEmpty);
|
||||
expect(latest.last.status, MessageStatus.failed);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'rotation with direct attempts > 0 tries direct paths before flooding',
|
||||
() async {
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.updateSettings(
|
||||
settings.settings.copyWith(
|
||||
autoRouteRotationEnabled: true,
|
||||
directRetries: 2,
|
||||
floodRetries: 1,
|
||||
),
|
||||
);
|
||||
|
||||
final service = MessageRetryService(
|
||||
sentWatchdogGrace: const Duration(milliseconds: 5),
|
||||
);
|
||||
addTearDown(service.dispose);
|
||||
final actions = <String>[];
|
||||
final sends = <int>[];
|
||||
service.initialize(
|
||||
RetryServiceConfig(
|
||||
sendMessage: (_, _, attempt, _) async {
|
||||
sends.add(attempt);
|
||||
},
|
||||
addMessage: (_, _) {},
|
||||
updateMessage: (_) {},
|
||||
clearContactPath: (_) async => actions.add('flood'),
|
||||
setContactPath: (_, bytes, _) async =>
|
||||
actions.add('direct:${bytes.join(',')}'),
|
||||
calculateTimeout:
|
||||
(_, _, {String? contactKey, int? deviceTimeoutMs}) => 15,
|
||||
appSettingsService: settings,
|
||||
selectRetryPath: (_, attemptIndex, directRetries, _) {
|
||||
if (attemptIndex >= directRetries) return null;
|
||||
return attemptIndex == 0
|
||||
? const PathSelection(
|
||||
pathBytes: [0x22],
|
||||
hopCount: 1,
|
||||
useFlood: false,
|
||||
)
|
||||
: const PathSelection(
|
||||
pathBytes: [0x33],
|
||||
hopCount: 1,
|
||||
useFlood: false,
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
await service.sendMessageWithRetry(
|
||||
contact: _contact(pathLength: 1, path: const [0x11]),
|
||||
text: 'hello',
|
||||
);
|
||||
await pumpEventQueue();
|
||||
await Future<void>.delayed(const Duration(milliseconds: 3500));
|
||||
|
||||
expect(sends, [0, 1, 2]);
|
||||
expect(actions, ['direct:34', 'direct:51', 'flood']);
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user