From af188e7d7481235efbcf582461d61d3480910bd7 Mon Sep 17 00:00:00 2001 From: Bud Cribar Date: Fri, 23 Feb 2024 04:34:24 -0700 Subject: [PATCH] All Tests passing --- src/RemoteBlazorWebView.Wpf/BlazorWebView.cs | 6 ++- src/RemoteWebView/RemoteWebView.cs | 4 -- .../NUnitTestProject/TestBlazorWpfControl.cs | 49 +++++++++++++------ .../NUnitTestProject/TestLocalBlazorForm.cs | 2 +- testassets/NUnitTestProject/TestServerForm.cs | 2 +- testassets/NUnitTestProject/TestServerWpf.cs | 2 +- 6 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/RemoteBlazorWebView.Wpf/BlazorWebView.cs b/src/RemoteBlazorWebView.Wpf/BlazorWebView.cs index b89597cc..eeb80363 100644 --- a/src/RemoteBlazorWebView.Wpf/BlazorWebView.cs +++ b/src/RemoteBlazorWebView.Wpf/BlazorWebView.cs @@ -109,7 +109,11 @@ public override string HostPage // Set a default Markup if necessary if (ServerUri != null && Id != Guid.Empty && string.IsNullOrEmpty(markup)) Markup = RemoteWebView.RemoteWebView.GenMarkup(ServerUri, Id); - + + // Default to the http server + if (GrpcBaseUri == null) + GrpcBaseUri = ServerUri; + SetValue(HostPageProperty, value); } } diff --git a/src/RemoteWebView/RemoteWebView.cs b/src/RemoteWebView/RemoteWebView.cs index 80ace053..aebb6254 100644 --- a/src/RemoteWebView/RemoteWebView.cs +++ b/src/RemoteWebView/RemoteWebView.cs @@ -148,10 +148,6 @@ public static void Restart(IBlazorWebView blazorWebView) { if (BlazorWebView.ServerUri == null) return null; - // Default to the http server - if (BlazorWebView.GrpcBaseUri == null) - BlazorWebView.GrpcBaseUri = BlazorWebView.ServerUri; - PingIntervalSeconds = BlazorWebView.PingIntervalSeconds; if (client == null) diff --git a/testassets/NUnitTestProject/TestBlazorWpfControl.cs b/testassets/NUnitTestProject/TestBlazorWpfControl.cs index 22c79673..c580f891 100644 --- a/testassets/NUnitTestProject/TestBlazorWpfControl.cs +++ b/testassets/NUnitTestProject/TestBlazorWpfControl.cs @@ -12,6 +12,10 @@ using System.IO; using System.Linq.Expressions; using System.Windows.Controls; +using System.Diagnostics; +using PeakSWC.RemoteWebView; +using Grpc.Net.Client; +using System.Threading.Channels; namespace WebdriverTestProject { @@ -155,7 +159,7 @@ await Application.Current.Dispatcher.InvokeAsync(() => { webView.Id = Guid.NewGuid(); webView.ServerUri = new System.Uri("https://localhost:5001"); - webView.GrpcBaseUri = new System.Uri("https://localhost:5002"); + //webView.GrpcBaseUri = new System.Uri("https://localhost:5002"); webView.HostPage = @"wwwroot\index.html"; @@ -184,16 +188,7 @@ await Application.Current.Dispatcher.InvokeAsync(() => { webView.Id = Guid.NewGuid(); webView.ServerUri = new System.Uri("https://localhost:5001"); webView.HostPage = @"wwwroot\index.html"; - try - { - webView.Group = "group"; - } - catch (Exception) - { - - - } - + webView.Group = "group"; }); } @@ -329,7 +324,7 @@ await Application.Current.Dispatcher.InvokeAsync(() => { webView.Id = Guid.NewGuid(); webView.ServerUri = new System.Uri("https://localhost:5001"); - webView.GrpcBaseUri = new System.Uri("https://localhost:5002"); + //webView.GrpcBaseUri = new System.Uri("https://localhost:5002"); webView.EnableMirrors = true; webView.HostPage = @"wwwroot\index.html"; @@ -353,7 +348,7 @@ await Application.Current.Dispatcher.InvokeAsync(() => { webView.Id = Guid.NewGuid(); webView.ServerUri = new System.Uri("https://localhost:5001"); - webView.GrpcBaseUri = new System.Uri("https://localhost:5002"); + webView.GrpcBaseUri = new System.Uri("https://localhost:5001"); webView.EnableMirrors = true; webView.PingIntervalSeconds = 33; webView.Group = "group"; @@ -363,11 +358,34 @@ await Application.Current.Dispatcher.InvokeAsync(() => { }); } + public static Process process; public TestContext? TestContext { get; set; } [ClassInitialize] - public static void Initialize(TestContext testContext) - { + public static async Task InitializeAsync(TestContext testContext) + { + string grpcUrl = @"https://localhost:5001/"; + GrpcChannel? channel; + string? envVarValue = Environment.GetEnvironmentVariable(variable: "Rust"); + if (envVarValue != null) + grpcUrl = @"https://localhost:5002/"; + + channel = GrpcChannel.ForAddress(grpcUrl); + process = Utilities.StartServer(); + + for (int i = 0; i < 10; i++) + { + // Wait for server to spin up + try + { + var ids = new WebViewIPC.WebViewIPCClient(channel).GetIds(new Empty()); + Assert.AreEqual(0, ids.Responses.Count, "Server has connections at startup"); + break; + } + catch (Exception) { } + await Task.Delay(1000); + } + BlazorWebViewFactory.Window = BlazorWebViewFactory.CreateBlazorWindow(); string directoryPath = @"."; // Specify the directory path @@ -397,6 +415,7 @@ public static void Initialize(TestContext testContext) public static void Cleanup() { BlazorWebViewFactory.Shutdown(); + process?.Kill(); } } } \ No newline at end of file diff --git a/testassets/NUnitTestProject/TestLocalBlazorForm.cs b/testassets/NUnitTestProject/TestLocalBlazorForm.cs index 0e63610f..9a31c8a1 100644 --- a/testassets/NUnitTestProject/TestLocalBlazorForm.cs +++ b/testassets/NUnitTestProject/TestLocalBlazorForm.cs @@ -45,7 +45,7 @@ public void Setup() try { - Log.Handlers.Add(new FileLogHandler(Path.Combine(Path.GetDirectoryName(binary) ?? "", "Selenium.log"))); + //Log.Handlers.Add(new FileLogHandler(Path.Combine(Path.GetDirectoryName(binary) ?? "", "Selenium.log"))); Log.SetLevel(LogEventLevel.Trace); driver = new EdgeDriver(options); diff --git a/testassets/NUnitTestProject/TestServerForm.cs b/testassets/NUnitTestProject/TestServerForm.cs index cf3a6d4c..31981d39 100644 --- a/testassets/NUnitTestProject/TestServerForm.cs +++ b/testassets/NUnitTestProject/TestServerForm.cs @@ -65,7 +65,7 @@ protected override async Task TestClient(int num) var totalBytesRead = response.ConnectionResponses.Sum(x => x.TotalBytesRead); Assert.AreEqual(24 * num, totalFilesRead, "Failed on total files read"); - Assert.AreEqual(1251746 * num, totalBytesRead, "Failed on total bytes read"); // This will vary depending on the size of the Javascript + Assert.AreEqual(1251832 * num, totalBytesRead, "Failed on total bytes read"); // This will vary depending on the size of the Javascript Console.WriteLine($"TotalBytesRead {totalBytesRead}"); Console.WriteLine($"TotalReadTime {totalReadTime}"); diff --git a/testassets/NUnitTestProject/TestServerWpf.cs b/testassets/NUnitTestProject/TestServerWpf.cs index d7591f5d..65816c61 100644 --- a/testassets/NUnitTestProject/TestServerWpf.cs +++ b/testassets/NUnitTestProject/TestServerWpf.cs @@ -63,7 +63,7 @@ protected override async Task TestClient(int num) var totalBytesRead = response.ConnectionResponses.Sum(x => x.TotalBytesRead); Assert.AreEqual(24 * num, totalFilesRead, "Failed on total files read"); - Assert.AreEqual(1251848 * num, totalBytesRead, "Failed on total bytes read"); + Assert.AreEqual(1251992 * num, totalBytesRead, "Failed on total bytes read"); Console.WriteLine($"TotalBytesRead {totalBytesRead}"); Console.WriteLine($"TotalReadTime {totalReadTime}");