fixed peer learning from first package (race condition)

This commit is contained in:
Constantin Leue
2026-08-02 22:09:24 +02:00
parent 0649ae4507
commit 2d7c50e030
2 changed files with 71 additions and 10 deletions
+39 -2
View File
@@ -188,6 +188,19 @@ void main() {
transport.dispose();
});
test(
'falls back to the default mLRS bridge IP when neither a host is '
'configured nor a gateway address is reported',
() async {
final fake = FakeMlrsNetworkController();
final transport = await connectWithFake(fake);
expect(transport.peerDescription, startsWith('192.168.4.55'));
transport.dispose();
},
);
test('a configured host overrides the reported gateway address', () async {
final fake = FakeMlrsNetworkController();
final transport = await connectWithFake(
@@ -223,9 +236,17 @@ void main() {
transport.dispose();
});
test('send() without a known peer throws LinkConnectException', () async {
test('send() before the socket is open throws LinkConnectException',
() async {
final fake = FakeMlrsNetworkController();
final transport = await connectWithFake(fake);
final transport = UdpTransport(
getHost: () async => null,
getPort: () async => 0,
getSsidPrefix: () async => 'mLRS-',
getRememberedSsid: () async => null,
rememberSsid: (_) async {},
networkController: fake,
);
expect(
() => transport.send(Uint8List.fromList([1])),
@@ -235,6 +256,22 @@ void main() {
transport.dispose();
});
test(
'send() works with the default mLRS bridge IP even before any packet '
'has been received',
() async {
final fake = FakeMlrsNetworkController();
final transport = await connectWithFake(fake);
await transport.send(Uint8List.fromList([1, 2, 3]));
expect(fake.sentPackets, hasLength(1));
expect(fake.sentPackets.single.host, '192.168.4.55');
transport.dispose();
},
);
test('send() forwards bytes to the learned peer via the native socket',
() async {
final fake = FakeMlrsNetworkController();