Add netquality 1.1.2 client and node behavior.
Show the address actually probed, keep address-selection misses out of formal loss, and add session metrics, a stop summary, pinned chart points, and in-app metric and release-history screens. Client version is 1.1.2+5. Attribution remains 言灸 under AGPL-3.0-only. Co-authored-by: yanjiu0721 <yanjiu0721@users.noreply.github.com>
This commit is contained in:
1 parent
8ca2185c01
commit
aeb08ec049
40 files changed
+3827
-545
No files matched your search
@@ -0,0 +1,99 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:netquality/content/release_history.dart';
|
||||
import 'package:netquality/metrics/sample_book.dart';
|
||||
import 'package:netquality/ui/address_text.dart';
|
||||
import 'package:netquality/ui/chart_selection.dart';
|
||||
import 'package:netquality/version.dart';
|
||||
|
||||
void main() {
|
||||
test('resolved addresses are not shown as the address in use', () {
|
||||
const resolved = [
|
||||
ResolvedAddress(address: '2001:db8::1', family: 'IPv6'),
|
||||
ResolvedAddress(address: '203.0.113.5', family: 'IPv4'),
|
||||
];
|
||||
final onlyResolved = describeAddress(resolved: resolved);
|
||||
expect(onlyResolved.used, isNull);
|
||||
expect(onlyResolved.resolved, contains('解析到'));
|
||||
expect(onlyResolved.resolved, contains('2001:db8::1'));
|
||||
expect(onlyResolved.resolved, isNot(contains('实际地址')));
|
||||
|
||||
final used = describeAddress(
|
||||
resolved: resolved,
|
||||
usedAddress: '203.0.113.5',
|
||||
usedFamily: 'IPv4',
|
||||
fallbackText: '已改用 IPv4',
|
||||
);
|
||||
expect(used.used, '实际地址 203.0.113.5(IPv4)');
|
||||
expect(used.resolved, contains('2001:db8::1'));
|
||||
expect(used.fallback, '已改用 IPv4');
|
||||
|
||||
final oldNode = describeAddress(
|
||||
resolved: const [],
|
||||
addressUnreported: true,
|
||||
);
|
||||
expect(oldNode.used, isNull);
|
||||
expect(oldNode.unreported, '节点没有报告实际使用的地址');
|
||||
|
||||
final missing = ProbeSample.fromJson({
|
||||
'seq': 1,
|
||||
'status': 'ok',
|
||||
'kind': 'probe',
|
||||
'rttMs': 3,
|
||||
'summary': {'sent': 1, 'ok': 1},
|
||||
});
|
||||
expect(missing.detail['address'], isNull);
|
||||
final parsed = readResolvedList({
|
||||
'resolved': [
|
||||
{'address': '2001:db8::1', 'family': 'IPv6'},
|
||||
],
|
||||
});
|
||||
expect(parsed.single.address, '2001:db8::1');
|
||||
expect(readResolvedList({'jobId': 'abc'}), isEmpty);
|
||||
});
|
||||
|
||||
test('a pinned chart point stays put until it scrolls off or the session changes', () {
|
||||
const first = ChartSelection(sec: 1.5, sessionId: 3);
|
||||
final kept = nextChartSelection(
|
||||
current: first,
|
||||
sessionId: 3,
|
||||
sampleSecs: [1.5, 2.5, 3.5],
|
||||
);
|
||||
expect(kept, same(first));
|
||||
|
||||
final moved = nextChartSelection(
|
||||
current: first,
|
||||
sessionId: 3,
|
||||
sampleSecs: [1.5, 2.5, 3.5],
|
||||
tappedSec: 2.4,
|
||||
);
|
||||
expect(moved!.sec, 2.5);
|
||||
expect(moved.sessionId, 3);
|
||||
|
||||
expect(
|
||||
nextChartSelection(current: moved, sessionId: 4, sampleSecs: [0.2, 0.4]),
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
nextChartSelection(current: first, sessionId: 3, sampleSecs: [2.5, 3.5]),
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
nextChartSelection(current: first, sessionId: 3, sampleSecs: const []),
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
|
||||
test('history only lists the real tag and this version', () {
|
||||
expect(appVersion, '1.1.2');
|
||||
expect(appBuild, 5);
|
||||
expect(appAttribution, '言灸');
|
||||
expect(releaseHistory.map((entry) => entry.version), ['1.1.2', '1.1.1']);
|
||||
expect(releaseHistory.last.published, '2026-11-09');
|
||||
expect(releaseHistory.last.source, contains('v1.1.1'));
|
||||
expect(releaseHistoryNote, contains('不写成另一个版本'));
|
||||
for (final entry in releaseHistory) {
|
||||
expect(entry.version, isNot('1.1.0'));
|
||||
expect(entry.version, isNot('1.0.0'));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
// Copyright (C) 2026 言灸
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
// The plot surface is not part of fl_chart's public API. The tap has to land
|
||||
// on that surface, not on the axis titles around it.
|
||||
// ignore_for_file: implementation_imports
|
||||
|
||||
import 'package:fl_chart/src/chart/line_chart/line_chart_renderer.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:netquality/probe/probe_controller.dart';
|
||||
import 'package:netquality/ui/chart_selection.dart';
|
||||
import 'package:netquality/ui/quality_charts.dart';
|
||||
|
||||
void main() {
|
||||
test('a tap pins the nearest time and a later tap replaces it', () {
|
||||
final first = nextChartSelection(
|
||||
current: null,
|
||||
sessionId: 3,
|
||||
sampleSecs: const [1, 2, 4],
|
||||
tappedSec: 2.2,
|
||||
);
|
||||
expect(first, isNotNull);
|
||||
expect(first!.sec, 2);
|
||||
expect(first.sessionId, 3);
|
||||
|
||||
final second = nextChartSelection(
|
||||
current: first,
|
||||
sessionId: 3,
|
||||
sampleSecs: const [1, 2, 4],
|
||||
tappedSec: 3.6,
|
||||
);
|
||||
expect(second!.sec, 4);
|
||||
|
||||
final kept = nextChartSelection(
|
||||
current: second,
|
||||
sessionId: 3,
|
||||
sampleSecs: const [1, 2, 4],
|
||||
);
|
||||
expect(kept, same(second));
|
||||
});
|
||||
|
||||
test('a new session or a point that rolled off does not jump', () {
|
||||
const pin = ChartSelection(sec: 1, sessionId: 3);
|
||||
expect(
|
||||
nextChartSelection(current: pin, sessionId: 4, sampleSecs: const [1, 2]),
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
nextChartSelection(current: pin, sessionId: 3, sampleSecs: const [2, 3]),
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
nextChartSelection(current: pin, sessionId: 3, sampleSecs: const []),
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('releasing a chart tap keeps the pinned readout', (tester) async {
|
||||
const samples = [
|
||||
ChartSample(sec: 0, rttMs: 10, ratePct: 0),
|
||||
ChartSample(sec: 1, rttMs: 30, ratePct: 50),
|
||||
];
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: QualityCharts(
|
||||
samples: samples,
|
||||
rateLabel: '探测无应答',
|
||||
running: false,
|
||||
sessionId: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('点曲线上的一点'), findsOneWidget);
|
||||
|
||||
final box = tester.getRect(find.byType(LineChartLeaf).first);
|
||||
const maxY = 30 * 1.2;
|
||||
Offset at(double sec, double value) {
|
||||
final x = box.left + box.width * sec;
|
||||
final y = box.top + (1 - value / maxY) * box.height;
|
||||
return Offset(x.clamp(box.left + 2, box.right - 2), y);
|
||||
}
|
||||
|
||||
await tester.tapAt(at(0, 10));
|
||||
await tester.pump();
|
||||
expect(find.textContaining('已选 0.0 秒'), findsOneWidget);
|
||||
expect(find.textContaining('延迟'), findsWidgets);
|
||||
|
||||
final mouse = await tester.startGesture(
|
||||
at(1, 30),
|
||||
kind: PointerDeviceKind.mouse,
|
||||
);
|
||||
await mouse.up();
|
||||
await tester.pump();
|
||||
expect(find.textContaining('已选 1.0 秒'), findsOneWidget);
|
||||
expect(find.textContaining('已选 0.0 秒'), findsNothing);
|
||||
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: QualityCharts(
|
||||
samples: [ChartSample(sec: 2, rttMs: 8, ratePct: 0)],
|
||||
rateLabel: '探测无应答',
|
||||
running: false,
|
||||
sessionId: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.textContaining('已选'), findsNothing);
|
||||
expect(find.textContaining('点曲线上的一点'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:netquality/metrics/latency.dart';
|
||||
import 'package:netquality/metrics/sample_book.dart';
|
||||
import 'package:netquality/ui/metrics_panel.dart';
|
||||
|
||||
void main() {
|
||||
test('percentile ranks match the documented integer formula', () {
|
||||
expect(nearestRank95(1), 1);
|
||||
expect(nearestRank95(2), 2);
|
||||
expect(nearestRank95(4), 4);
|
||||
expect(nearestRank95(5), 5);
|
||||
expect(nearestRank95(20), 19);
|
||||
|
||||
final one = LatencyStats.from([10]);
|
||||
expect(one!.min, 10);
|
||||
expect(one.mean, 10);
|
||||
expect(one.median, 10);
|
||||
expect(one.p95, 10);
|
||||
expect(one.max, 10);
|
||||
|
||||
final two = LatencyStats.from([10, 30]);
|
||||
expect(two!.median, 20);
|
||||
expect(two.p95, 30);
|
||||
expect(two.mean, 20);
|
||||
|
||||
final four = LatencyStats.from([1, 2, 3, 4]);
|
||||
expect(four!.median, 2.5);
|
||||
expect(four.p95, 4);
|
||||
expect(four.min, 1);
|
||||
expect(four.max, 4);
|
||||
|
||||
final five = LatencyStats.from([1, 2, 3, 4, 10]);
|
||||
expect(five!.median, 3);
|
||||
expect(five.p95, 10);
|
||||
expect(five.mean, 4);
|
||||
});
|
||||
|
||||
test('sample book keeps current rtt separate from the distribution', () {
|
||||
final book = SampleBook('nq-udp');
|
||||
book.add(const Outcome(status: Outcome.ok, kind: Outcome.probe, rttMs: 1));
|
||||
book.add(const Outcome(status: Outcome.ok, kind: Outcome.probe, rttMs: 2));
|
||||
book.add(const Outcome(status: Outcome.ok, kind: Outcome.probe, rttMs: 3));
|
||||
book.add(const Outcome(status: Outcome.ok, kind: Outcome.probe, rttMs: 4));
|
||||
final summary = book.summary();
|
||||
expect(summary.rttMs, 4);
|
||||
expect(summary.minRttMs, 1);
|
||||
expect(summary.maxRttMs, 4);
|
||||
expect(summary.medianRttMs, 2.5);
|
||||
expect(summary.p95RttMs, 4);
|
||||
expect(summary.meanRttMs, 2.5);
|
||||
expect(summary.latencyStats, isTrue);
|
||||
expect(summary.jitterMs, isNotNull);
|
||||
});
|
||||
|
||||
test('unsupported rates stay blank instead of a false zero', () {
|
||||
final silent = SampleBook('udp-generic')
|
||||
..add(const Outcome(status: Outcome.unknown, kind: Outcome.query));
|
||||
final lines = metricLines(
|
||||
summary: silent.summary(),
|
||||
profileId: 'udp-generic',
|
||||
elapsed: const Duration(seconds: 2),
|
||||
);
|
||||
expect(_value(lines, '超时'), '不适用');
|
||||
expect(_value(lines, '无应答(未知)'), '100%');
|
||||
expect(_value(lines, '探测无应答'), isNull);
|
||||
expect(_value(lines, '当前延迟'), '—');
|
||||
|
||||
final connect = SampleBook('tcp-connect');
|
||||
final empty = metricLines(
|
||||
summary: connect.summary(),
|
||||
profileId: 'tcp-connect',
|
||||
elapsed: Duration.zero,
|
||||
);
|
||||
expect(_value(empty, '失败率'), '—');
|
||||
expect(_value(empty, '探测无应答'), isNull);
|
||||
|
||||
final oldNode = ProbeSummary.fromJson({
|
||||
'sent': 1,
|
||||
'completed': 1,
|
||||
'ok': 1,
|
||||
'rttMs': 8,
|
||||
'probeLossPct': 0,
|
||||
});
|
||||
final remote = metricLines(
|
||||
summary: oldNode,
|
||||
profileId: 'nq-udp',
|
||||
elapsed: const Duration(seconds: 3),
|
||||
);
|
||||
expect(_value(remote, '当前延迟'), '8.00 ms');
|
||||
expect(_value(remote, 'P95 延迟'), '节点未提供');
|
||||
expect(_value(remote, '探测无应答'), '0%');
|
||||
});
|
||||
}
|
||||
|
||||
String? _value(List<MetricLine> lines, String label) {
|
||||
for (final line in lines) {
|
||||
if (line.label == label) {
|
||||
return line.value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:netquality/models/node_edit.dart';
|
||||
import 'package:netquality/models/port_field.dart';
|
||||
import 'package:netquality/models/probe_profile.dart';
|
||||
import 'package:netquality/models/session_config.dart';
|
||||
import 'package:netquality/storage/token_vault.dart';
|
||||
|
||||
void main() {
|
||||
test(
|
||||
'editing keeps the node id and replaces only a non-blank token',
|
||||
() async {
|
||||
const original = RemoteNode(
|
||||
id: 'node-7',
|
||||
name: '机房',
|
||||
baseUrl: 'https://probe.example:8443',
|
||||
visibility: 'private',
|
||||
);
|
||||
final renamed = applyNodeEdit(
|
||||
original,
|
||||
name: '机房乙',
|
||||
baseUrl: 'https://probe.example:8443',
|
||||
);
|
||||
expect(renamed.id, 'node-7');
|
||||
expect(renamed.name, '机房乙');
|
||||
expect(renamed.visibility, 'private');
|
||||
|
||||
final moved = applyNodeEdit(
|
||||
renamed,
|
||||
name: '机房乙',
|
||||
baseUrl: 'https://other.example:8443',
|
||||
);
|
||||
expect(moved.id, 'node-7');
|
||||
expect(moved.visibility, '');
|
||||
|
||||
final vault = MemoryTokenVault();
|
||||
await vault.write(nodeTokenKey('node-7'), 'saved-secret');
|
||||
expect(await saveEditedNodeToken(vault, 'node-7', ' '), isFalse);
|
||||
expect(await vault.read(nodeTokenKey('node-7')), 'saved-secret');
|
||||
expect(replacementNodeToken(' '), isNull);
|
||||
expect(
|
||||
await saveEditedNodeToken(vault, 'node-7', ' next-secret '),
|
||||
isTrue,
|
||||
);
|
||||
expect(await vault.read(nodeTokenKey('node-7')), 'next-secret');
|
||||
final encoded = moved.toJson();
|
||||
expect(encoded.containsKey('token'), isFalse);
|
||||
expect(encoded.values, isNot(contains('saved-secret')));
|
||||
expect(encoded.values, isNot(contains('next-secret')));
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'port follows the profile default unless the user typed another port',
|
||||
() {
|
||||
expect(ProbeProfile.nqTcp.port, 19090);
|
||||
expect(ProbeProfile.nqUdp.port, 19091);
|
||||
expect(portHint(ProbeProfile.nqTcp), '合作反射 TCP 默认 19090');
|
||||
expect(portHint(ProbeProfile.nqUdp), '合作反射 UDP 默认 19091');
|
||||
expect(
|
||||
portAfterProfileChange(
|
||||
current: '19090',
|
||||
previousDefault: 19090,
|
||||
nextDefault: 19091,
|
||||
),
|
||||
'19091',
|
||||
);
|
||||
expect(
|
||||
portAfterProfileChange(
|
||||
current: ' 19090 ',
|
||||
previousDefault: 19090,
|
||||
nextDefault: 19132,
|
||||
),
|
||||
'19132',
|
||||
);
|
||||
expect(
|
||||
portAfterProfileChange(
|
||||
current: '',
|
||||
previousDefault: 19090,
|
||||
nextDefault: 19091,
|
||||
),
|
||||
'19091',
|
||||
);
|
||||
expect(
|
||||
portAfterProfileChange(
|
||||
current: '25565',
|
||||
previousDefault: 19090,
|
||||
nextDefault: 19091,
|
||||
),
|
||||
'25565',
|
||||
);
|
||||
expect(
|
||||
portAfterProfileChange(
|
||||
current: '25565',
|
||||
previousDefault: 19091,
|
||||
nextDefault: 80,
|
||||
),
|
||||
'25565',
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
+253
-226
@@ -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, [
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:netquality/metrics/sample_book.dart';
|
||||
import 'package:netquality/metrics/selection_ledger.dart';
|
||||
|
||||
void main() {
|
||||
const v6 = Outcome(
|
||||
status: Outcome.timeout,
|
||||
kind: Outcome.probe,
|
||||
note: '未收到回显',
|
||||
detail: {'address': '2001:db8::1', 'family': 'IPv6'},
|
||||
);
|
||||
const v4ok = Outcome(
|
||||
status: Outcome.ok,
|
||||
kind: Outcome.probe,
|
||||
rttMs: 5,
|
||||
note: '收到回显',
|
||||
detail: {'address': '203.0.113.5', 'family': 'IPv4'},
|
||||
);
|
||||
const v4timeout = Outcome(
|
||||
status: Outcome.timeout,
|
||||
kind: Outcome.probe,
|
||||
note: '未收到回显',
|
||||
detail: {'address': '203.0.113.5', 'family': 'IPv4'},
|
||||
);
|
||||
|
||||
test('ipv6 miss then ipv4 success is not formal loss', () {
|
||||
final ledger = SelectionLedger(2);
|
||||
expect(ledger.take(v6, responded: false).commit, isEmpty);
|
||||
final decision = ledger.take(v4ok, responded: true);
|
||||
expect(decision.skipped, 1);
|
||||
expect(decision.commit.single.selectionSkipped, 1);
|
||||
expect(decision.commit.single.detail['fallback'], contains('2001:db8::1'));
|
||||
expect(decision.commit.single.detail['fallback'], contains('203.0.113.5'));
|
||||
expect(decision.commit.single.detail['fallback'], contains('没有计入'));
|
||||
final book = SampleBook('nq-udp');
|
||||
book.add(decision.commit.single);
|
||||
final summary = book.summary();
|
||||
expect(summary.sent, 1);
|
||||
expect(summary.ok, 1);
|
||||
expect(summary.timeout, 0);
|
||||
expect(summary.probeLossPct, 0);
|
||||
expect(summary.selectionSkipped, 1);
|
||||
});
|
||||
|
||||
test('every candidate failing is loss, not a false zero', () {
|
||||
final ledger = SelectionLedger(2);
|
||||
expect(ledger.take(v6, responded: false).commit, isEmpty);
|
||||
final decision = ledger.take(v4timeout, responded: false);
|
||||
expect(decision.commit, hasLength(2));
|
||||
final book = SampleBook('nq-udp');
|
||||
for (final outcome in decision.commit) {
|
||||
book.add(outcome);
|
||||
}
|
||||
final summary = book.summary();
|
||||
expect(summary.ok, 0);
|
||||
expect(summary.sent, 2);
|
||||
expect(summary.timeout, 2);
|
||||
expect(summary.probeLossPct, 100);
|
||||
expect(summary.selectionSkipped, 0);
|
||||
});
|
||||
|
||||
test('timeouts after an address is selected still count', () {
|
||||
final ledger = SelectionLedger(2);
|
||||
final first = ledger.take(v4ok, responded: true);
|
||||
expect(ledger.measuring, isTrue);
|
||||
final again = ledger.take(v4timeout, responded: false);
|
||||
expect(again.commit, hasLength(1));
|
||||
final book = SampleBook('nq-udp');
|
||||
book.add(first.commit.single);
|
||||
book.add(again.commit.single);
|
||||
expect(book.summary().probeLossPct, 50);
|
||||
expect(book.summary().sent, 2);
|
||||
});
|
||||
|
||||
test('one address never hides a failure', () {
|
||||
final ledger = SelectionLedger(1);
|
||||
final decision = ledger.take(v4timeout, responded: false);
|
||||
expect(decision.commit, hasLength(1));
|
||||
final book = SampleBook('nq-tcp');
|
||||
book.add(decision.commit.single);
|
||||
expect(book.summary().probeLossPct, 100);
|
||||
});
|
||||
|
||||
test('a stopped in-flight attempt is not recorded', () {
|
||||
expect(
|
||||
countsAfterStop(
|
||||
const Outcome(
|
||||
status: Outcome.timeout,
|
||||
kind: Outcome.probe,
|
||||
note: '已停止',
|
||||
),
|
||||
cancelled: false,
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
expect(
|
||||
countsAfterStop(
|
||||
const Outcome(status: Outcome.timeout, kind: Outcome.probe),
|
||||
cancelled: true,
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
expect(
|
||||
countsAfterStop(
|
||||
const Outcome(status: Outcome.ok, kind: Outcome.probe, rttMs: 1),
|
||||
cancelled: false,
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
expect(countsAfterStop(null, cancelled: false), isFalse);
|
||||
});
|
||||
|
||||
test(
|
||||
'leaving a measured address does not drop the failure that caused it',
|
||||
() {
|
||||
final ledger = SelectionLedger(2);
|
||||
ledger.take(v4ok, responded: true);
|
||||
final miss = ledger.take(v4timeout, responded: false);
|
||||
expect(miss.commit, hasLength(1));
|
||||
ledger.endMeasurement();
|
||||
expect(ledger.measuring, isFalse);
|
||||
final held = ledger.take(v6, responded: false);
|
||||
expect(held.commit, isEmpty);
|
||||
final recovered = ledger.take(v4ok, responded: true);
|
||||
expect(recovered.skipped, 1);
|
||||
final book = SampleBook('nq-udp');
|
||||
book.add(v4ok);
|
||||
book.add(miss.commit.single);
|
||||
book.add(recovered.commit.single);
|
||||
expect(book.summary().sent, 3);
|
||||
expect(book.summary().timeout, 1);
|
||||
expect(book.summary().probeLossPct, closeTo(100 / 3, 0.0001));
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user