diff --git a/tests/stream_netns/network.py b/tests/stream_netns/network.py index 85927516..0ccaf126 100644 --- a/tests/stream_netns/network.py +++ b/tests/stream_netns/network.py @@ -3,6 +3,7 @@ import json import os from pathlib import Path +import select import subprocess import time @@ -89,7 +90,7 @@ class Network: child = subprocess.Popen(["unshare", "--net", "--", "python3", "-u", "-c", keeper], stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True) self.children.append(child) - if child.stdout.readline().strip() != str(child.pid): + if not select.select([child.stdout], [], [], 5)[0] or child.stdout.readline().strip() != str(child.pid): raise RuntimeError(f"Cannot create namespace {name}") inode = os.readlink(f"/proc/{child.pid}/ns/net") if inode in {self.controller, self.host_namespace}: diff --git a/tests/stream_netns/probe.py b/tests/stream_netns/probe.py index dff95a8e..4e0ecaa8 100644 --- a/tests/stream_netns/probe.py +++ b/tests/stream_netns/probe.py @@ -54,8 +54,6 @@ def serve(address): samples.append((time.monotonic() - started) * 1000) observed = reply["observed"] break - else: - pass if len(samples) + lost < _ + 1: lost += 1 print(json.dumps({"samples_ms": samples, "observed": observed, "lost": lost}), flush=True) @@ -90,8 +88,14 @@ class Probes: return json.loads(line) def calibrate(self): - results = {"wan": [], "nat": []} + results = {"lan": [], "wan": [], "nat": []} public = {n.country: n for n in NODES if not n.nat and n.client_type == 0} + for country, first in public.items(): + second = next(n for n in NODES if n.country == country and not n.nat and n.name != first.name) + result = self.exchange(first.name, second.ip, count=20) + if len(result["samples_ms"]) < 19 or statistics.median(result["samples_ms"]) > 10: + raise RuntimeError(f"LAN {country}: measured connection is not a good local link: {result}") + results["lan"].append(dict(result, country=country, median_ms=statistics.median(result["samples_ms"]))) for link in WANS: result = self.exchange(public[link.a].name, public[link.b].ip, count=40) if len(result["samples_ms"]) < 30: