发布网络质量探测 1.1.2:更新测试、版本号与协议说明

署名:言灸
This commit is contained in:
YanJiu committed 2026-11-20 19:00:36 +08:00
1 parent c1a60eef43
commit 3776ece7a4
4 files changed
+373 -229

No files matched your search

+1 -1
View File
@@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.1.1+4
version: 1.1.2+5
environment:
sdk: ^3.13.7
+253 -226
View File
@@ -25,238 +25,261 @@ void main() {
expect(build.exitCode, 0, reason: '${build.stdout}\n${build.stderr}');
});
test('local nq tcp and udp get real rtt and do not call connect failure loss', () async {
final reflector = await _reflector();
addTearDown(() => reflector.process.kill());
final tcp = await _collect(
ProbeRequest(
host: '127.0.0.1',
port: reflector.tcp,
profileId: 'nq-tcp',
interval: const Duration(milliseconds: 200),
timeout: const Duration(milliseconds: 800),
packetSize: 80,
echoToken: '',
dnsName: '',
payloadHex: '',
expectHex: '',
),
count: 2,
);
expect(tcp.last.status, Outcome.ok);
expect(tcp.last.rttMs, greaterThan(0));
expect(tcp.last.summary.probeLossPct, 0);
test(
'local nq tcp and udp get real rtt and do not call connect failure loss',
() async {
final reflector = await _reflector();
addTearDown(() => reflector.process.kill());
final tcp = await _collect(
ProbeRequest(
host: '127.0.0.1',
port: reflector.tcp,
profileId: 'nq-tcp',
interval: const Duration(milliseconds: 200),
timeout: const Duration(milliseconds: 800),
packetSize: 80,
echoToken: '',
dnsName: '',
payloadHex: '',
expectHex: '',
),
count: 2,
);
expect(tcp.last.status, Outcome.ok);
expect(tcp.last.rttMs, greaterThan(0));
expect(tcp.last.summary.probeLossPct, 0);
final udp = await _collect(
ProbeRequest(
host: '127.0.0.1',
port: reflector.udp,
profileId: 'nq-udp',
interval: const Duration(milliseconds: 200),
timeout: const Duration(milliseconds: 800),
packetSize: 80,
echoToken: '',
dnsName: '',
payloadHex: '',
expectHex: '',
),
count: 1,
);
expect(udp.single.status, Outcome.ok);
expect(udp.single.summary.probeLossPct, 0);
final udp = await _collect(
ProbeRequest(
host: '127.0.0.1',
port: reflector.udp,
profileId: 'nq-udp',
interval: const Duration(milliseconds: 200),
timeout: const Duration(milliseconds: 800),
packetSize: 80,
echoToken: '',
dnsName: '',
payloadHex: '',
expectHex: '',
),
count: 1,
);
expect(udp.single.status, Outcome.ok);
expect(udp.single.summary.probeLossPct, 0);
final refused = await _collect(
ProbeRequest(
host: '127.0.0.1',
port: 1,
profileId: 'tcp-connect',
interval: const Duration(milliseconds: 200),
timeout: const Duration(milliseconds: 400),
packetSize: 64,
echoToken: '',
dnsName: '',
payloadHex: '',
expectHex: '',
),
count: 1,
);
expect(refused.single.status, Outcome.refused);
expect(refused.single.summary.failurePct, 100);
expect(refused.single.summary.probeLossPct, isNull);
});
final refused = await _collect(
ProbeRequest(
host: '127.0.0.1',
port: 1,
profileId: 'tcp-connect',
interval: const Duration(milliseconds: 200),
timeout: const Duration(milliseconds: 400),
packetSize: 64,
echoToken: '',
dnsName: '',
payloadHex: '',
expectHex: '',
),
count: 1,
);
expect(refused.single.status, Outcome.refused);
expect(refused.single.summary.failurePct, 100);
expect(refused.single.summary.probeLossPct, isNull);
},
);
test('silence is unknown, games answer, and a remote node measures rtt', () async {
final hole = await RawDatagramSocket.bind(InternetAddress.loopbackIPv4, 0);
addTearDown(hole.close);
hole.listen((event) {
if (event == RawSocketEvent.read) {
hole.receive();
}
});
final unknown = await _collect(
ProbeRequest(
host: '127.0.0.1',
port: hole.port,
profileId: 'udp-generic',
interval: const Duration(milliseconds: 200),
timeout: const Duration(milliseconds: 200),
packetSize: 16,
echoToken: '',
dnsName: '',
payloadHex: '',
expectHex: '',
),
count: 1,
);
expect(unknown.single.status, Outcome.unknown);
expect(unknown.single.summary.probeLossPct, isNull);
expect(unknown.single.summary.unknownPct, 100);
expect(unknown.single.detail['address'], '127.0.0.1');
final java = await _javaServer();
addTearDown(java.close);
final javaSample = await _collect(
ProbeRequest(
host: '127.0.0.1',
port: java.port,
profileId: 'minecraft-java',
interval: const Duration(milliseconds: 200),
timeout: const Duration(milliseconds: 800),
packetSize: 64,
echoToken: '',
dnsName: '',
payloadHex: '',
expectHex: '',
),
count: 1,
);
expect(javaSample.single.status, Outcome.ok);
expect(javaSample.single.detail['motd'], 'Hello');
expect(javaSample.single.rttMs, greaterThan(0));
expect(javaSample.single.summary.failurePct, 0);
final bedrock = await _bedrockServer();
addTearDown(bedrock.close);
final bedrockSample = await _collect(
ProbeRequest(
host: '127.0.0.1',
port: bedrock.port,
profileId: 'minecraft-bedrock',
interval: const Duration(milliseconds: 200),
timeout: const Duration(milliseconds: 800),
packetSize: 64,
echoToken: '',
dnsName: '',
payloadHex: '',
expectHex: '',
),
count: 1,
);
expect(bedrockSample.single.status, Outcome.ok);
expect(bedrockSample.single.detail['motd'], 'Bed');
final node = await _node();
addTearDown(node.kill);
final samples = <ProbeSample>[];
final remote = RemoteProbe();
final done = Completer<void>();
unawaited(() async {
try {
await remote.run(
baseUrl: 'http://127.0.0.1:${node.control}',
nodeToken: '',
body: ProbeBody(
target: '127.0.0.1',
port: node.udp,
profile: 'nq-udp',
intervalMs: 200,
timeoutMs: 800,
durationSec: 3,
packetSize: 80,
echoToken: '',
dnsName: '',
payloadHex: '',
expectHex: '',
),
onSample: (sample) {
samples.add(sample);
if (samples.length == 1 && !done.isCompleted) {
done.complete();
}
},
cancelled: () => done.isCompleted,
);
} finally {
if (!done.isCompleted) {
done.complete();
test(
'silence is unknown, games answer, and a remote node measures rtt',
() async {
final hole = await RawDatagramSocket.bind(
InternetAddress.loopbackIPv4,
0,
);
addTearDown(hole.close);
hole.listen((event) {
if (event == RawSocketEvent.read) {
hole.receive();
}
}
}());
await done.future.timeout(const Duration(seconds: 5));
await remote.stop('');
expect(samples, isNotEmpty);
expect(samples.first.status, Outcome.ok);
expect(samples.first.rttMs, greaterThan(0));
expect(samples.first.summary.probeLossPct, 0);
});
});
final unknown = await _collect(
ProbeRequest(
host: '127.0.0.1',
port: hole.port,
profileId: 'udp-generic',
interval: const Duration(milliseconds: 200),
timeout: const Duration(milliseconds: 200),
packetSize: 16,
echoToken: '',
dnsName: '',
payloadHex: '',
expectHex: '',
),
count: 1,
);
expect(unknown.single.status, Outcome.unknown);
expect(unknown.single.summary.probeLossPct, isNull);
expect(unknown.single.summary.unknownPct, 100);
expect(unknown.single.detail['address'], '127.0.0.1');
test('plain udp leaves a silent address and keeps one that answers', () async {
final drop = await RawDatagramSocket.bind(InternetAddress.loopbackIPv4, 0);
addTearDown(drop.close);
final port = drop.port;
drop.listen((event) {
if (event == RawSocketEvent.read) {
drop.receive();
}
});
final RawDatagramSocket echo;
try {
echo = await RawDatagramSocket.bind(InternetAddress.loopbackIPv6, port);
} on SocketException {
markTestSkipped('IPv6 loopback is not available');
return;
}
addTearDown(echo.close);
echo.listen((event) {
if (event != RawSocketEvent.read) {
final java = await _javaServer();
addTearDown(java.close);
final javaSample = await _collect(
ProbeRequest(
host: '127.0.0.1',
port: java.port,
profileId: 'minecraft-java',
interval: const Duration(milliseconds: 200),
timeout: const Duration(milliseconds: 800),
packetSize: 64,
echoToken: '',
dnsName: '',
payloadHex: '',
expectHex: '',
),
count: 1,
);
expect(javaSample.single.status, Outcome.ok);
expect(javaSample.single.detail['motd'], 'Hello');
expect(javaSample.single.rttMs, greaterThan(0));
expect(javaSample.single.summary.failurePct, 0);
final bedrock = await _bedrockServer();
addTearDown(bedrock.close);
final bedrockSample = await _collect(
ProbeRequest(
host: '127.0.0.1',
port: bedrock.port,
profileId: 'minecraft-bedrock',
interval: const Duration(milliseconds: 200),
timeout: const Duration(milliseconds: 800),
packetSize: 64,
echoToken: '',
dnsName: '',
payloadHex: '',
expectHex: '',
),
count: 1,
);
expect(bedrockSample.single.status, Outcome.ok);
expect(bedrockSample.single.detail['motd'], 'Bed');
final node = await _node();
addTearDown(node.kill);
final samples = <ProbeSample>[];
final remote = RemoteProbe();
final done = Completer<void>();
unawaited(() async {
try {
await remote.run(
baseUrl: 'http://127.0.0.1:${node.control}',
nodeToken: '',
body: ProbeBody(
target: '127.0.0.1',
port: node.udp,
profile: 'nq-udp',
intervalMs: 200,
timeoutMs: 800,
durationSec: 3,
packetSize: 80,
echoToken: '',
dnsName: '',
payloadHex: '',
expectHex: '',
),
onSample: (sample) {
samples.add(sample);
if (samples.length == 1 && !done.isCompleted) {
done.complete();
}
},
cancelled: () => done.isCompleted,
);
} finally {
if (!done.isCompleted) {
done.complete();
}
}
}());
await done.future.timeout(const Duration(seconds: 5));
await remote.stop('');
expect(samples, isNotEmpty);
expect(samples.first.status, Outcome.ok);
expect(samples.first.rttMs, greaterThan(0));
expect(samples.first.summary.probeLossPct, 0);
},
);
test(
'a silent candidate is not a measured miss once another address answers',
() async {
final drop = await RawDatagramSocket.bind(
InternetAddress.loopbackIPv4,
0,
);
addTearDown(drop.close);
final port = drop.port;
drop.listen((event) {
if (event == RawSocketEvent.read) {
drop.receive();
}
});
final RawDatagramSocket echo;
try {
echo = await RawDatagramSocket.bind(InternetAddress.loopbackIPv6, port);
} on SocketException {
markTestSkipped('IPv6 loopback is not available');
return;
}
final datagram = echo.receive();
if (datagram == null) {
return;
}
echo.send(datagram.data, datagram.address, datagram.port);
});
addTearDown(echo.close);
echo.listen((event) {
if (event != RawSocketEvent.read) {
return;
}
final datagram = echo.receive();
if (datagram == null) {
return;
}
echo.send(datagram.data, datagram.address, datagram.port);
});
final seen = <String>[];
final samples = await _collect(
ProbeRequest(
host: 'example.test',
port: port,
profileId: 'udp-generic',
interval: const Duration(milliseconds: 40),
timeout: const Duration(milliseconds: 250),
packetSize: 16,
echoToken: '',
dnsName: '',
payloadHex: '',
expectHex: '',
),
count: 2,
loop: ProbeLoop(
lookup: (host) async {
expect(host, 'example.test');
return [InternetAddress('127.0.0.1'), InternetAddress('::1')];
},
onEndpoint: (address) => seen.add(address.address),
),
);
expect(samples.first.status, Outcome.unknown);
expect(samples.first.detail['address'], '127.0.0.1');
expect(samples.last.status, Outcome.ok);
expect(samples.last.detail['address'], '::1');
expect(seen, ['127.0.0.1', '::1']);
});
final seen = <String>[];
final samples = await _collect(
ProbeRequest(
host: 'example.test',
port: port,
profileId: 'udp-generic',
interval: const Duration(milliseconds: 40),
timeout: const Duration(milliseconds: 250),
packetSize: 16,
echoToken: '',
dnsName: '',
payloadHex: '',
expectHex: '',
),
count: 2,
loop: ProbeLoop(
lookup: (host) async {
expect(host, 'example.test');
return [InternetAddress('127.0.0.1'), InternetAddress('::1')];
},
onEndpoint: (address) => seen.add(address.address),
),
);
expect(samples.first.status, Outcome.ok);
expect(samples.first.detail['address'], '::1');
expect(samples.first.detail['family'], 'IPv6');
expect(samples.first.detail['fallback'], contains('127.0.0.1'));
expect(samples.first.detail['fallback'], contains('没有计入'));
expect(samples.first.summary.sent, 1);
expect(samples.first.summary.unknown, 0);
expect(samples.first.summary.selectionSkipped, 1);
expect(samples.first.summary.unknownPct, 0);
expect(samples.last.status, Outcome.ok);
expect(samples.last.detail['address'], '::1');
expect(samples.last.summary.unknown, 0);
expect(seen, ['127.0.0.1', '::1']);
},
);
test('a responding address is not replaced while it still answers', () async {
final echo = await RawDatagramSocket.bind(InternetAddress.loopbackIPv4, 0);
@@ -293,7 +316,10 @@ void main() {
),
);
expect(samples.map((sample) => sample.status), everyElement(Outcome.ok));
expect(samples.map((sample) => sample.detail['address']), everyElement('127.0.0.1'));
expect(
samples.map((sample) => sample.detail['address']),
everyElement('127.0.0.1'),
);
});
}
@@ -337,7 +363,8 @@ Future<({Process process, int tcp, int udp})> _reflector() async {
return (process: process, tcp: tcp, udp: udp);
}
Future<({Process process, int control, int udp, void Function() kill})> _node() async {
Future<({Process process, int control, int udp, void Function() kill})>
_node() async {
final udp = await _freeUdp();
final control = await _freeTcp();
final process = await Process.start(binary, [
+116 -1
View File
@@ -1,3 +1,5 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:netquality/main.dart';
@@ -27,7 +29,9 @@ void main() {
const config = SessionConfig(
remote: true,
nodeId: 'n1',
nodes: [RemoteNode(id: 'n1', name: '机房', baseUrl: 'https://probe.example:8443')],
nodes: [
RemoteNode(id: 'n1', name: '机房', baseUrl: 'https://probe.example:8443'),
],
host: '203.0.113.8',
port: 25565,
profileId: 'minecraft-java',
@@ -47,4 +51,115 @@ void main() {
expect(again.toJson().containsKey('nodeToken'), isFalse);
expect(SessionConfig.defaults.validate(), isNull);
});
testWidgets(
'profile default port updates until the user types another port',
(tester) async {
SharedPreferences.setMockInitialValues({});
tester.view.physicalSize = const Size(1280, 1600);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(const NetQualityApp());
await tester.pumpAndSettle();
expect(find.text('合作反射 TCP 默认 19090'), findsOneWidget);
await tester.ensureVisible(find.byKey(const Key('profile')));
await tester.tap(find.byKey(const Key('profile')));
await tester.pumpAndSettle();
await tester.tap(find.text('合作反射 UDP').last);
await tester.pumpAndSettle();
expect(find.text('19091'), findsWidgets);
expect(find.text('合作反射 UDP 默认 19091'), findsOneWidget);
await tester.enterText(find.byKey(const Key('port-field')), '25565');
await tester.tap(find.byKey(const Key('profile')));
await tester.pumpAndSettle();
await tester.tap(find.text('合作反射 TCP').last);
await tester.pumpAndSettle();
expect(find.text('25565'), findsOneWidget);
},
);
testWidgets('editing a node keeps its id and does not reveal the token', (
tester,
) async {
SharedPreferences.setMockInitialValues({});
tester.view.physicalSize = const Size(1280, 1600);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(const NetQualityApp());
await tester.pumpAndSettle();
await tester.tap(find.text('远程节点').first);
await tester.pumpAndSettle();
await tester.tap(find.text('管理节点'));
await tester.pumpAndSettle();
await tester.enterText(find.byKey(const Key('node-name')), '机房');
await tester.enterText(
find.byKey(const Key('node-url')),
'http://127.0.0.1:8443',
);
await tester.enterText(find.byKey(const Key('node-token')), 'saved-secret');
await tester.tap(find.byKey(const Key('node-save')));
await tester.pumpAndSettle();
await tester.tap(find.text('编辑'));
await tester.pumpAndSettle();
final token = tester.widget<TextField>(find.byKey(const Key('node-token')));
expect(token.controller?.text, isEmpty);
expect(find.text('saved-secret'), findsNothing);
await tester.enterText(find.byKey(const Key('node-name')), '机房乙');
await tester.tap(find.text('保存修改'));
await tester.pumpAndSettle();
expect(find.textContaining('机房乙'), findsWidgets);
final prefs = await SharedPreferences.getInstance();
final raw = prefs.getString('netquality.settings.v2') ?? '';
expect(raw, contains('机房乙'));
expect(raw, isNot(contains('saved-secret')));
final decoded = jsonDecode(raw) as Map<String, dynamic>;
final nodes = decoded['nodes'] as List<dynamic>;
expect(nodes, hasLength(1));
final node = nodes.single as Map<String, dynamic>;
expect(node['name'], '机房乙');
expect(node['baseUrl'], 'http://127.0.0.1:8443');
expect(decoded['nodeId'], node['id']);
});
testWidgets('guide and history screens use the real versions', (
tester,
) async {
SharedPreferences.setMockInitialValues({});
tester.view.physicalSize = const Size(900, 1400);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(const NetQualityApp());
await tester.pumpAndSettle();
await tester.tap(find.byType(PopupMenuButton<String>));
await tester.pumpAndSettle();
await tester.tap(find.text('指标说明'));
await tester.pumpAndSettle();
expect(find.textContaining('没有协议应答'), findsWidgets);
await tester.scrollUntilVisible(find.text('选址失败和正式丢包'), 200);
expect(find.text('选址失败和正式丢包'), findsOneWidget);
await tester.scrollUntilVisible(find.textContaining('RFC 3550'), 200);
expect(find.textContaining('RFC 3550'), findsOneWidget);
await tester.pageBack();
await tester.pumpAndSettle();
await tester.tap(find.byType(PopupMenuButton<String>));
await tester.pumpAndSettle();
await tester.tap(find.text('更新历史'));
await tester.pumpAndSettle();
expect(find.text('网络质量探测 1.1.2'), findsOneWidget);
await tester.scrollUntilVisible(find.text('网络质量探测 1.1.1'), 200);
expect(find.text('网络质量探测 1.1.1'), findsOneWidget);
expect(find.textContaining('言灸'), findsOneWidget);
expect(find.textContaining('v1.1.1'), findsWidgets);
expect(find.text('网络质量探测 1.1.0'), findsNothing);
});
}