发布网络质量探测 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
+159 -15

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
+39 -12
View File
@@ -25,7 +25,9 @@ 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 {
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(
@@ -83,10 +85,16 @@ void main() {
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);
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) {
@@ -198,10 +206,16 @@ void main() {
expect(samples.first.status, Outcome.ok);
expect(samples.first.rttMs, greaterThan(0));
expect(samples.first.summary.probeLossPct, 0);
});
},
);
test('plain udp leaves a silent address and keeps one that answers', () async {
final drop = await RawDatagramSocket.bind(InternetAddress.loopbackIPv4, 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) {
@@ -251,12 +265,21 @@ void main() {
onEndpoint: (address) => seen.add(address.address),
),
);
expect(samples.first.status, Outcome.unknown);
expect(samples.first.detail['address'], '127.0.0.1');
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);
});
}
+3 -1
View File
@@ -44,7 +44,9 @@
- **普通 TCP**:只记录连接耗时、成功或失败、连续失败。没有自定义帧。
- **普通 UDP、DNS、自定义 UDP、基岩版**:没有收到符合协议的包时记为无应答/未知,不叫丢包。内容不对记为协议错误。
- **Minecraft Java**:状态握手加上 ping/pong。往返时间只算 ping 到对上 nonce 的 pong。连不上或协议不对记为失败率。
- **抖动**:RFC 3550。相邻两次成功的往返时间差 `D`,`J = J + (|D| - J) / 16`。
- **抖动**:RFC 3550。相邻两次成功的往返时间差 `D`,`J = J + (|D| - J) / 16`。第一次成功时 J 为 0。
- **延迟分布**:只统计成功样本。当前延迟是最近一次成功。最小、最大是极值。平均是算术平均。中位数在奇数个时取排序后的中间值,偶数个时取中间两个的平均。P95 用最近秩,秩 = ceil(0.95 × 次数),用整数 `(95 × 次数 + 99) / 100` 计算,从 1 起计。
- **选址**:一个名字解析出多个地址时,还没有任何地址应答之前的失败只用于挑选地址。后面有地址成功时,这些失败不进入已发送、超时和丢包,并在 `detail.fallback` 里说明。选定之后的失败照常计入。每个候选都失败时,这些失败计入正式结果,不能显示成 0% 成功。每条样本的 `detail.address` 和 `detail.family` 是这次实际连通或发包的地址;没有这个字段就表示节点没有报告,不能用解析结果代替。`summary` 另有 `minRttMs`、`meanRttMs`、`medianRttMs`、`p95RttMs`、`maxRttMs` 和 `selectionSkipped`。旧客户端会忽略不认识的字段。
## 控制接口