diff --git a/test/hwp_source_unit_test.dart b/test/hwp_source_unit_test.dart index 1dbf0ac..0c7824c 100644 --- a/test/hwp_source_unit_test.dart +++ b/test/hwp_source_unit_test.dart @@ -231,8 +231,9 @@ void main() { final n = _Gated(); final d = QueuedHwpDoc(n); final a = d.exportPdf(0, 5, 'a', timeout: const Duration(seconds: 30)); // 오래 도는 앞 묶음 - final b = d.exportPdf(5, 10, 'b', timeout: const Duration(milliseconds: 300)); - await Future.delayed(const Duration(milliseconds: 700)); // 뒤 묶음의 제한보다 오래 줄에서 기다림 + // 흔들림 (10/21 전체 실행): 제한이 300ms 면 무거울 때 [release] 까지의 틈이 그것을 넘었다 - 제한 1.5초 · 줄에서 2초 기다림 + final b = d.exportPdf(5, 10, 'b', timeout: const Duration(milliseconds: 1500)); + await Future.delayed(const Duration(milliseconds: 2000)); // 뒤 묶음의 제한보다 오래 줄에서 기다림 expect(n.started, [1]); n.release(1); await a; diff --git a/test/support/fake_dns.dart b/test/support/fake_dns.dart index adfc983..404dc28 100644 --- a/test/support/fake_dns.dart +++ b/test/support/fake_dns.dart @@ -46,16 +46,31 @@ class FakeDns { // netsh int ipv4 show excludedportrange) 가 달라, TCP 를 먼저 OS 가 고른 번호로 열고 그 번호로 UDP 를 연다. // 그 번호의 UDP 가 막혀 있거나 (10013) 쓰는 중이면 다른 번호로 다시 for (var i = 0;; i++) { - final tcp = await ServerSocket.bind(InternetAddress.loopbackIPv4, 0); - final udp = await _tryUdp(tcp.port); - if (udp != null) { - _udp = udp; - _tcp = tcp; - events.add('bound tcp+udp ${tcp.port} (try $i)'); - break; + // 10/21 전체 실행: OS 가 TCP 번호를 차례로 주는데 (62345, 62346 …) 그 둘레가 통째로 UDP 막힌 범위라 50번 모두 실패했다 - + // 홀수 번째는 거꾸로 UDP 를 OS 가 고른 (열 수 있는) 번호로 먼저 열고 그 번호로 TCP 를 연다 + if (i.isOdd) { + final udp = await RawDatagramSocket.bind(InternetAddress.loopbackIPv4, 0); + try { + _tcp = await ServerSocket.bind(InternetAddress.loopbackIPv4, udp.port); + _udp = udp; + events.add('bound udp+tcp ${udp.port} (try $i)'); + break; + } on SocketException catch (e) { + events.add('tcp bind ${udp.port} failed: ${e.osError?.errorCode} ${e.message}'); + udp.close(); + } + } else { + final tcp = await ServerSocket.bind(InternetAddress.loopbackIPv4, 0); + final udp = await _tryUdp(tcp.port); + if (udp != null) { + _udp = udp; + _tcp = tcp; + events.add('bound tcp+udp ${tcp.port} (try $i)'); + break; + } + await tcp.close(); } - await tcp.close(); - if (i > 50) throw StateError('UDP 포트를 열지 못함: $events'); + if (i > 50) throw StateError('UDP · TCP 같은 포트를 열지 못함: $events'); } } _udp.listen((e) {