-
Notifications
You must be signed in to change notification settings - Fork 5.1k
[browser][MT] Add new test for multi-threading SignalR in Blazor WBT #98343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
188fec4
Add new test asset app - blazor hosted with SignalR.
ilonatommy 116b9b8
Group TestAppScenarios to dirs by app used in tests.
ilonatommy cae7478
[wip] Add a new test - equivalent of `SignalRClientWorksWithLongPolli…
ilonatommy 56e927f
Merge branch 'main' into fix-97085
ilonatommy 6e13c9a
Add headers, append threadId, temporarily switch off bundle assert.
ilonatommy 56e5370
Fix after merge
ilonatommy e34a760
Fix duplicating `dotnet.native.worker.js` in boot.config
ilonatommy 89660f4
Cleanup.
ilonatommy 4a0ffd3
Merge branch 'main' into fix-97085
ilonatommy 17b8a54
Cleanup.
ilonatommy f7ff6b6
Cleanup in messages.
ilonatommy b5b16df
Debugging version for CI - no merge
ilonatommy 4d7f422
Interactive version of tests.
ilonatommy 925aa1d
not needed anymore
ilonatommy 247242c
Flatten the structure.
ilonatommy 4faf241
Initial cleanup
ilonatommy 69dbb28
Initial cleanup.
ilonatommy bffcf16
Merge branch 'main' into fix-97085
ilonatommy f30fcd6
Merge branch 'fix-97085' of https://github.com/ilonatommy/runtime int…
ilonatommy 891450d
Remove tmp dev messages.
ilonatommy 5c85490
Fix "Static files may be unavailable."
ilonatommy 6ea01ce
Merge branch 'main' into fix-97085
ilonatommy e1bb53a
Merge branch 'main' into fix-97085
ilonatommy bb91d7c
Revert removal of `--ignore-certificate-errors` - it is needed for c…
ilonatommy 132ed1d
Revert unnecessary change.
ilonatommy bc742aa
Remove TestOutput duplicates.
ilonatommy 14886a6
Merge branch 'main' into fix-97085
ilonatommy de1abba
Fix
ilonatommy a1d0689
Merge branch 'main' into fix-97085
ilonatommy aa44255
Try fixing " Static files may be unavailable"
ilonatommy 14b1d73
Cleanup + better logs + Host.cshtml removal.
ilonatommy 299081d
Remove custom `ContentRootPath` because it does not help.
ilonatommy 8341627
Temporarily: Increase logging.
ilonatommy 7c557d6
Merge branch 'main' into fix-97085
ilonatommy 543ff66
Revert logging + apply @maraf's fix.
ilonatommy a0a2c04
Feedback - unnecessary files.
ilonatommy 05d8fd4
Feedback - these logs don't need to be "TestOutput" type.
ilonatommy 4fa5c01
Update comment + merge testOutputs into one buffer + add ToString on …
ilonatommy 66c5b10
Initial reduction of setup code.
ilonatommy 21febc0
Minor refactor.
ilonatommy cb5707a
Major refactor.
ilonatommy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/BlazorHostedApp/SignalRClientTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
using Microsoft.Playwright; | ||
using Xunit.Abstractions; | ||
using Xunit; | ||
|
||
#nullable enable | ||
|
||
namespace Wasm.Build.Tests.TestAppScenarios; | ||
|
||
public class SignalRClientTests : AppTestBase | ||
{ | ||
public SignalRClientTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) | ||
: base(output, buildContext) | ||
{ | ||
} | ||
|
||
[ConditionalTheory(typeof(BuildTestBase), nameof(IsWorkloadWithMultiThreadingForDefaultFramework))] | ||
[InlineData("Debug", "LongPolling")] | ||
[InlineData("Release", "LongPolling")] | ||
[InlineData("Debug", "WebSockets")] | ||
[InlineData("Release", "WebSockets")] | ||
public async Task SignalRPassMessages(string config, string transport) | ||
{ | ||
CopyTestAsset("BlazorHostedApp", "SignalRClientTests"); | ||
RunOptions options = new( | ||
Configuration: config, | ||
TestScenario: "SignalRPassMessages", | ||
BrowserQueryString: new Dictionary<string, string> { ["message"] = "test", ["transport"] = transport }, | ||
ExtraArgs: $"--logRootPath {s_buildEnv.LogRootPath}" | ||
); | ||
|
||
string rootProjectPath = Directory.GetParent(_projectDir!)?.FullName ?? ""; | ||
string clientProjectDir = Path.Combine(rootProjectPath, "BlazorHosted.Client"); | ||
string frameworkDir = FindBlazorBinFrameworkDir(config, forPublish: false, projectDir: clientProjectDir); | ||
ilonatommy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
BuildProject( | ||
configuration: config, | ||
binFrameworkDir: frameworkDir, | ||
runtimeType: RuntimeVariant.MultiThreaded); | ||
|
||
var result = await RunSdkStyleAppForBuild(options); | ||
|
||
// make sure we're not in the main thread (id != 1) | ||
var confirmation = result.TestOutput.FirstOrDefault(m => m.Contains($"[{transport}] Client confirms receiving message=test CurrentManagedThreadId=")); | ||
Assert.NotNull(confirmation); | ||
string currentManagedThreadId = confirmation.Split("CurrentManagedThreadId=")[1]; | ||
Assert.NotEqual("1", currentManagedThreadId); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ilonatommy marked this conversation as resolved.
Show resolved
Hide resolved
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/mono/wasm/testassets/BlazorHostedApp/BlazorHosted.Client/App.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Router AppAssembly="@typeof(App).Assembly"> | ||
<Found Context="routeData"> | ||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /> | ||
<FocusOnNavigate RouteData="@routeData" Selector="h1" /> | ||
</Found> | ||
<NotFound> | ||
<PageTitle>Not found</PageTitle> | ||
<LayoutView Layout="@typeof(MainLayout)"> | ||
<p role="alert">Sorry, there's nothing at this address.</p> | ||
</LayoutView> | ||
</NotFound> | ||
</Router> |
19 changes: 19 additions & 0 deletions
19
src/mono/wasm/testassets/BlazorHostedApp/BlazorHosted.Client/BlazorHosted.Client.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<WasmEnableThreads>true</WasmEnableThreads> | ||
<!-- nullablility warnings --> | ||
<NoWarn>CS8604</NoWarn> | ||
</PropertyGroup> | ||
|
||
<!-- versions are pinned but when run from WBT level, it's taking in-tree runtime --> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.0-alpha.1.23614.6" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.0-alpha.1.23614.6" PrivateAssets="all" /> | ||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.1" /> | ||
<PackageReference Include="System.Net.Http.Json" Version="8.0.0" /> | ||
</ItemGroup> | ||
</Project> |
42 changes: 42 additions & 0 deletions
42
src/mono/wasm/testassets/BlazorHostedApp/BlazorHosted.Client/Helper.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Specialized; | ||
using Microsoft.AspNetCore.Http.Connections; | ||
|
||
namespace BlazorHosted.Client; | ||
|
||
public static class Helper | ||
{ | ||
public static string GetValue(NameValueCollection parameters, string key) | ||
{ | ||
var values = parameters.GetValues(key); | ||
if (values == null || values.Length == 0) | ||
{ | ||
throw new Exception($"Parameter '{key}' is required in the query string"); | ||
} | ||
if (values.Length > 1) | ||
{ | ||
throw new Exception($"Parameter '{key}' should be unique in the query string"); | ||
} | ||
return values[0]; | ||
} | ||
|
||
public static HttpTransportType StringToTransportType(string transport) | ||
{ | ||
switch (transport.ToLowerInvariant()) | ||
{ | ||
case "longpolling": | ||
return HttpTransportType.LongPolling; | ||
case "websockets": | ||
return HttpTransportType.WebSockets; | ||
default: | ||
throw new Exception($"{transport} is invalid transport type"); | ||
} | ||
} | ||
|
||
public static void TestOutputWriteLine(string message) | ||
{ | ||
Console.WriteLine("TestOutput -> " + message); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/mono/wasm/testassets/BlazorHostedApp/BlazorHosted.Client/Layout/MainLayout.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
@inherits LayoutComponentBase | ||
|
||
<div class="page"> | ||
<main> | ||
<div class="top-row px-4"> | ||
<a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a> | ||
</div> | ||
|
||
<article class="content px-4"> | ||
@Body | ||
</article> | ||
</main> | ||
</div> |
108 changes: 108 additions & 0 deletions
108
src/mono/wasm/testassets/BlazorHostedApp/BlazorHosted.Client/Pages/Chat.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
@page "/" | ||
@using Microsoft.AspNetCore.SignalR | ||
@using Microsoft.AspNetCore.SignalR.Client | ||
@using Microsoft.AspNetCore.Http.Connections; | ||
@using System.Web; | ||
@inject NavigationManager NavigationManager | ||
|
||
<h1>Chat Room</h1> | ||
<div> | ||
@foreach (var chatMessage in chatMessages) | ||
{ | ||
<p>@chatMessage</p> | ||
} | ||
</div> | ||
|
||
@code { | ||
private string _hubUrl = string.Empty; | ||
private HubConnection? _hubConnection; | ||
private string message = string.Empty; | ||
private string transport = string.Empty; | ||
private string scenario = string.Empty; | ||
private List<string> chatMessages = new List<string>(); | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
GetQueryParameters(); | ||
await Connect(); | ||
if (_hubConnection == null) | ||
{ | ||
throw new Exception($"Hub connection is not initialized for transport={transport}"); | ||
} | ||
|
||
// wait one second before activating the test scenario | ||
await Task.Delay(1000); | ||
switch (scenario.ToLower()) | ||
{ | ||
case "signalrpassmessages": | ||
await SignalRPassMessages(); | ||
break; | ||
default: | ||
await FailAndExit($"{scenario} is invalid test scenario name"); | ||
break; | ||
} | ||
} | ||
|
||
private async Task SignalRPassMessages() => | ||
await Task.Run(async () => | ||
{ | ||
Helper.TestOutputWriteLine($"Client: sends message={message} with CurrentManagedThreadId={Environment.CurrentManagedThreadId}"); | ||
await _hubConnection.SendAsync( | ||
"SendMessage", | ||
message, | ||
Environment.CurrentManagedThreadId); | ||
}); | ||
|
||
private void GetQueryParameters() | ||
{ | ||
var uri = new Uri(NavigationManager.Uri); | ||
if (string.IsNullOrEmpty(uri.Query)) | ||
{ | ||
throw new Exception("Query string with parameters 'test', 'message' and 'transport' are required"); | ||
} | ||
var parameters = HttpUtility.ParseQueryString(uri.Query); | ||
if (parameters == null) | ||
{ | ||
throw new Exception("Query string with parameters 'test', 'message' and 'transport' are required"); | ||
} | ||
scenario = Helper.GetValue(parameters, "test"); | ||
transport = Helper.GetValue(parameters, "transport"); | ||
message = $"[{transport} {Helper.GetValue(parameters, "message")}]" ; | ||
} | ||
|
||
private async Task Connect() | ||
{ | ||
_hubUrl = NavigationManager.BaseUri + "chathub"; | ||
HttpTransportType httpTransportType = Helper.StringToTransportType(transport); | ||
_hubConnection = new HubConnectionBuilder() | ||
.WithUrl(_hubUrl, options => | ||
{ | ||
options.Transports = httpTransportType; | ||
}) | ||
.Build(); | ||
|
||
_hubConnection.On<string>("ReceiveMessage", async (message) => | ||
{ | ||
chatMessages.Add(message); | ||
Helper.TestOutputWriteLine($"Client: sends confirmation of receiving the reply from server = {message}, tread receiving the reply = {Environment.CurrentManagedThreadId}"); | ||
// on this message server calls "Environment.Exit(0)" | ||
await _hubConnection.SendAsync("ConfirmClientReceivedMessageAndExitWithSuccess", message); | ||
Console.WriteLine("WASM EXIT 0"); | ||
}); | ||
|
||
await _hubConnection.StartAsync(); | ||
} | ||
|
||
private async Task FailAndExit(string message) | ||
{ | ||
int code = 1; | ||
await _hubConnection.SendAsync("Exit", code); | ||
Console.WriteLine($"WASM EXIT {code}"); | ||
throw new Exception(message); | ||
} | ||
|
||
public ValueTask? DisposeAsync() | ||
{ | ||
return _hubConnection?.DisposeAsync(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.