发布网络质量探测 1.1.2:更新测试、版本号与协议说明
署名:言灸
This commit is contained in:
1 parent
c1a60eef43
commit
3776ece7a4
4 files changed
+373
-229
No files matched your search
+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, [
|
||||
|
||||
Reference in new issue
Block a user