diff --git a/desktop/Ads.Desktop.Smoke/Program.cs b/desktop/Ads.Desktop.Smoke/Program.cs index 343ed7d..7ac4df0 100644 --- a/desktop/Ads.Desktop.Smoke/Program.cs +++ b/desktop/Ads.Desktop.Smoke/Program.cs @@ -9,6 +9,15 @@ internal static class Program [STAThread] public static int Main(string[] args) { + if (args.Length == 2 && args[0] == "--port-child") + { + var listener = new System.Net.Sockets.TcpListener(System.Net.IPAddress.Loopback, int.Parse(args[1])); + listener.Start(); + Console.WriteLine("READY"); + Console.Out.Flush(); + Thread.Sleep(Timeout.Infinite); + return 0; + } AppBuilder.Configure().UseSkia().UseHeadless(new AvaloniaHeadlessPlatformOptions { UseHeadlessDrawing = false }).SetupWithoutStarting(); using var finished = new CancellationTokenSource(); Exception? failure = null; @@ -72,6 +81,17 @@ internal static class Program Require(!vm.HasConnection && vm.Notice.Contains("已被占用"), "Occupied port was not rejected safely"); } finally { occupied.Stop(); } + var childInfo = ProcessTools.CreateStartInfo("dotnet", [typeof(Program).Assembly.Location, "--port-child", vm.Port.ToString()]); + using var child = System.Diagnostics.Process.Start(childInfo)!; + try + { + Require(await child.StandardOutput.ReadLineAsync().WaitAsync(TimeSpan.FromSeconds(10)) == "READY", "Listener child did not start"); + await vm.ClearPortCommand.ExecuteAsync(null); + Require(child.HasExited && vm.PortCleanupStatus.Contains("已释放"), "GUI clear-port action did not terminate listener"); + Require(window.FindControl