Skip to content
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

[browser][MT] Add new test for multi-threading SignalR in Blazor WBT #98343

Merged
merged 41 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 Feb 13, 2024
116b9b8
Group TestAppScenarios to dirs by app used in tests.
ilonatommy Feb 13, 2024
cae7478
[wip] Add a new test - equivalent of `SignalRClientWorksWithLongPolli…
ilonatommy Feb 13, 2024
56e927f
Merge branch 'main' into fix-97085
ilonatommy Feb 13, 2024
6e13c9a
Add headers, append threadId, temporarily switch off bundle assert.
ilonatommy Feb 13, 2024
56e5370
Fix after merge
ilonatommy Feb 13, 2024
e34a760
Fix duplicating `dotnet.native.worker.js` in boot.config
ilonatommy Feb 13, 2024
89660f4
Cleanup.
ilonatommy Feb 14, 2024
4a0ffd3
Merge branch 'main' into fix-97085
ilonatommy Feb 16, 2024
17b8a54
Cleanup.
ilonatommy Feb 16, 2024
f7ff6b6
Cleanup in messages.
ilonatommy Feb 16, 2024
b5b16df
Debugging version for CI - no merge
ilonatommy Feb 20, 2024
4d7f422
Interactive version of tests.
ilonatommy Feb 23, 2024
925aa1d
not needed anymore
ilonatommy Feb 23, 2024
247242c
Flatten the structure.
ilonatommy Feb 23, 2024
4faf241
Initial cleanup
ilonatommy Feb 23, 2024
69dbb28
Initial cleanup.
ilonatommy Feb 23, 2024
bffcf16
Merge branch 'main' into fix-97085
ilonatommy Feb 23, 2024
f30fcd6
Merge branch 'fix-97085' of https://github.com/ilonatommy/runtime int…
ilonatommy Feb 23, 2024
891450d
Remove tmp dev messages.
ilonatommy Feb 23, 2024
5c85490
Fix "Static files may be unavailable."
ilonatommy Feb 23, 2024
6ea01ce
Merge branch 'main' into fix-97085
ilonatommy Feb 23, 2024
e1bb53a
Merge branch 'main' into fix-97085
ilonatommy Feb 26, 2024
bb91d7c
Revert removal of `--ignore-certificate-errors` - it is needed for c…
ilonatommy Feb 26, 2024
132ed1d
Revert unnecessary change.
ilonatommy Feb 26, 2024
bc742aa
Remove TestOutput duplicates.
ilonatommy Feb 26, 2024
14886a6
Merge branch 'main' into fix-97085
ilonatommy Feb 26, 2024
de1abba
Fix
ilonatommy Feb 26, 2024
a1d0689
Merge branch 'main' into fix-97085
ilonatommy Feb 27, 2024
aa44255
Try fixing " Static files may be unavailable"
ilonatommy Feb 27, 2024
14b1d73
Cleanup + better logs + Host.cshtml removal.
ilonatommy Feb 27, 2024
299081d
Remove custom `ContentRootPath` because it does not help.
ilonatommy Feb 27, 2024
8341627
Temporarily: Increase logging.
ilonatommy Feb 28, 2024
7c557d6
Merge branch 'main' into fix-97085
ilonatommy Feb 28, 2024
543ff66
Revert logging + apply @maraf's fix.
ilonatommy Feb 28, 2024
a0a2c04
Feedback - unnecessary files.
ilonatommy Feb 29, 2024
05d8fd4
Feedback - these logs don't need to be "TestOutput" type.
ilonatommy Feb 29, 2024
4fa5c01
Update comment + merge testOutputs into one buffer + add ToString on …
ilonatommy Feb 29, 2024
66c5b10
Initial reduction of setup code.
ilonatommy Feb 29, 2024
21febc0
Minor refactor.
ilonatommy Feb 29, 2024
cb5707a
Major refactor.
ilonatommy Feb 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion eng/testing/scenarios/BuildWasmAppsJobsList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ Wasm.Build.Tests.TestAppScenarios.AppSettingsTests
Wasm.Build.Tests.TestAppScenarios.LazyLoadingTests
Wasm.Build.Tests.TestAppScenarios.LibraryInitializerTests
Wasm.Build.Tests.TestAppScenarios.SatelliteLoadingTests
Wasm.Build.Tests.TestAppScenarios.DownloadResourceProgressTests
Wasm.Build.Tests.TestAppScenarios.SignalRClientTests
Wasm.Build.Tests.WasmBuildAppTest
Wasm.Build.Tests.WasmNativeDefaultsTests
Wasm.Build.Tests.WasmRunOutOfAppBundleTests
Wasm.Build.Tests.WasmSIMDTests
Wasm.Build.Tests.WasmTemplateTests
Wasm.Build.Tests.WorkloadTests
Wasm.Build.Tests.TestAppScenarios.DownloadResourceProgressTests
Wasm.Build.Tests.MT.Blazor.SimpleMultiThreadedTests
Wasm.Build.Tests.TestAppScenarios.DebugLevelTests
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<PropertyGroup>
<_WasmNativeAssetFileNames>;@(WasmNativeAsset->'%(FileName)%(Extension)');</_WasmNativeAssetFileNames>
</PropertyGroup>

<ItemGroup>
<_WasmConfigFileCandidates Include="@(StaticWebAsset)" Condition="'%(SourceType)' == 'Discovered'" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var builder
await BlazorRunForBuildWithDotnetRun(new BlazorRunOptions()
{
Config = "debug",
OnConsoleMessage = msg =>
OnConsoleMessage = (_, msg) =>
{
if (msg.Text.Contains("appSettings Exists 'True'"))
existsChecked = true;
Expand Down
7 changes: 6 additions & 1 deletion src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorRunOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Playwright;

Expand All @@ -13,11 +14,15 @@ public record BlazorRunOptions
BlazorRunHost Host = BlazorRunHost.DotnetRun,
bool DetectRuntimeFailures = true,
bool CheckCounter = true,
Dictionary<string, string>? ServerEnvironment = null,
Func<IPage, Task>? Test = null,
Action<IConsoleMessage>? OnConsoleMessage = null,
Action<IPage>? OnPageLoaded = null,
Action<IPage, IConsoleMessage>? OnConsoleMessage = null,
Action<string>? OnServerMessage = null,
Action<string>? OnErrorMessage = null,
string Config = "Debug",
string? ExtraArgs = null,
string BrowserPath = "",
string QueryString = ""
);

Expand Down
27 changes: 22 additions & 5 deletions src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,22 @@ public async Task BlazorRunTest(string runArgs,
{
if (!string.IsNullOrEmpty(runOptions.ExtraArgs))
runArgs += $" {runOptions.ExtraArgs}";

runOptions.ServerEnvironment?.ToList().ForEach(
kv => s_buildEnv.EnvVars[kv.Key] = kv.Value);

using var runCommand = new RunCommand(s_buildEnv, _testOutput)
.WithWorkingDirectory(workingDirectory);

await using var runner = new BrowserRunner(_testOutput);
var page = await runner.RunAsync(runCommand, runArgs, onConsoleMessage: OnConsoleMessage, onError: OnErrorMessage, modifyBrowserUrl: browserUrl => browserUrl + runOptions.QueryString);
var page = await runner.RunAsync(
runCommand,
runArgs,
onPageLoaded: runOptions.OnPageLoaded,
onConsoleMessage: OnConsoleMessage,
onServerMessage: runOptions.OnServerMessage,
onError: OnErrorMessage,
modifyBrowserUrl: browserUrl => browserUrl + runOptions.BrowserPath + runOptions.QueryString);

_testOutput.WriteLine("Waiting for page to load");
await page.WaitForLoadStateAsync(LoadState.DOMContentLoaded, new () { Timeout = 1 * 60 * 1000 });
Expand All @@ -217,11 +228,11 @@ public async Task BlazorRunTest(string runArgs,
_testOutput.WriteLine($"Waiting for additional 10secs to see if any errors are reported");
await Task.Delay(10_000);

void OnConsoleMessage(IConsoleMessage msg)
void OnConsoleMessage(IPage page, IConsoleMessage msg)
{
_testOutput.WriteLine($"[{msg.Type}] {msg.Text}");

runOptions.OnConsoleMessage?.Invoke(msg);
runOptions.OnConsoleMessage?.Invoke(page, msg);

if (runOptions.DetectRuntimeFailures)
{
Expand All @@ -237,6 +248,12 @@ void OnErrorMessage(string msg)
}
}

public string FindBlazorBinFrameworkDir(string config, bool forPublish, string framework = DefaultTargetFrameworkForBlazor)
=> _provider.FindBinFrameworkDir(config: config, forPublish: forPublish, framework: framework);
public string FindBlazorBinFrameworkDir(string config, bool forPublish, string framework = DefaultTargetFrameworkForBlazor, string? projectDir = null)
=> _provider.FindBinFrameworkDir(config: config, forPublish: forPublish, framework: framework, projectDir: projectDir);

public string FindBlazorHostedBinFrameworkDir(string config, bool forPublish, string clientDirRelativeToProjectDir, string framework = DefaultTargetFrameworkForBlazor)
{
string? clientProjectDir = _projectDir == null ? null : Path.Combine(_projectDir, clientDirRelativeToProjectDir);
return _provider.FindBinFrameworkDir(config: config, forPublish: forPublish, framework: framework, projectDir: clientProjectDir);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ await BlazorRunForPublishWithWebServer(
runOptions: new BlazorRunOptions(
Config: config,
ExtraArgs: "--web-server-use-cors --web-server-use-cop",
OnConsoleMessage: (message) =>
OnConsoleMessage: (_, message) =>
{
if (message.Text.Contains("WasmEnableThreads=true"))
hasEmittedWasmEnableThreads = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ await BlazorRunTest(new BlazorRunOptions()
{
Config = config,
Host = publish ? BlazorRunHost.WebServer : BlazorRunHost.DotnetRun,
OnConsoleMessage = msg =>
OnConsoleMessage = (_, msg) =>
{
sbOutput.AppendLine(msg.Text);
}
Expand Down
26 changes: 19 additions & 7 deletions src/mono/wasm/Wasm.Build.Tests/BrowserRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,21 @@ internal class BrowserRunner : IAsyncDisposable

public async Task<string> StartServerAndGetUrlAsync(
ToolCommand cmd,
string args
string args,
Action<string>? onServerMessage = null
) {
TaskCompletionSource<string> urlAvailable = new();
Action<string?> outputHandler = msg =>
{
if (string.IsNullOrEmpty(msg))
return;

onServerMessage?.Invoke(msg);

lock (OutputLines)
{
OutputLines.Add(msg);
}

Match m = s_appHostUrlRegex.Match(msg);
if (!m.Success)
Expand Down Expand Up @@ -91,7 +96,8 @@ public async Task<IBrowser> SpawnBrowserAsync(
) {
var url = new Uri(browserUrl);
Playwright = await Microsoft.Playwright.Playwright.CreateAsync();
string[] chromeArgs = new[] { $"--explicitly-allowed-ports={url.Port}" };
// codespaces: ignore certificate error -> Microsoft.Playwright.PlaywrightException : net::ERR_CERT_AUTHORITY_INVALID
string[] chromeArgs = new[] { $"--explicitly-allowed-ports={url.Port}", "--ignore-certificate-errors" };
_testOutput.WriteLine($"Launching chrome ('{s_chromePath.Value}') via playwright with args = {string.Join(',', chromeArgs)}");
return Browser = await Playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions{
ExecutablePath = s_chromePath.Value,
Expand All @@ -105,21 +111,24 @@ public async Task<IPage> RunAsync(
ToolCommand cmd,
string args,
bool headless = true,
Action<IConsoleMessage>? onConsoleMessage = null,
Action<IPage, IConsoleMessage>? onConsoleMessage = null,
Action<IPage>? onPageLoaded = null,
Action<string>? onServerMessage = null,
Action<string>? onError = null,
Func<string, string>? modifyBrowserUrl = null)
{
var urlString = await StartServerAndGetUrlAsync(cmd, args);
var urlString = await StartServerAndGetUrlAsync(cmd, args, onServerMessage);
var browser = await SpawnBrowserAsync(urlString, headless);
var context = await browser.NewContextAsync();
return await RunAsync(context, urlString, headless, onConsoleMessage, onError, modifyBrowserUrl);
return await RunAsync(context, urlString, headless, onPageLoaded, onConsoleMessage, onError, modifyBrowserUrl);
}

public async Task<IPage> RunAsync(
IBrowserContext context,
string browserUrl,
bool headless = true,
Action<IConsoleMessage>? onConsoleMessage = null,
Action<IPage>? onPageLoaded = null,
Action<IPage, IConsoleMessage>? onConsoleMessage = null,
Action<string>? onError = null,
Func<string, string>? modifyBrowserUrl = null,
bool resetExitedState = false
Expand All @@ -131,8 +140,11 @@ public async Task<IPage> RunAsync(
browserUrl = modifyBrowserUrl(browserUrl);

IPage page = await context.NewPageAsync();
if (onPageLoaded is not null)
page.Load += (_, _) => onPageLoaded(page);

if (onConsoleMessage is not null)
page.Console += (_, msg) => onConsoleMessage(msg);
page.Console += (_, msg) => onConsoleMessage(page, msg);

onError ??= _testOutput.WriteLine;
if (onError is not null)
Expand Down
7 changes: 7 additions & 0 deletions src/mono/wasm/Wasm.Build.Tests/Common/TestOutputWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Text;
using Xunit.Abstractions;

#nullable enable
Expand All @@ -10,17 +11,23 @@ namespace Wasm.Build.Tests;

public class TestOutputWrapper(ITestOutputHelper baseOutput) : ITestOutputHelper
{
private readonly StringBuilder _outputBuffer = new StringBuilder();

public void WriteLine(string message)
{
baseOutput.WriteLine(message);
_outputBuffer.AppendLine(message);
if (EnvironmentVariables.ShowBuildOutput)
Console.WriteLine(message);
}

public void WriteLine(string format, params object[] args)
{
baseOutput.WriteLine(format, args);
_outputBuffer.AppendFormat(format, args).AppendLine();
if (EnvironmentVariables.ShowBuildOutput)
Console.WriteLine(format, args);
}

public override string ToString() => _outputBuffer.ToString();
}
4 changes: 2 additions & 2 deletions src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,10 @@ private void AssertFileNames(IEnumerable<string> expected, IEnumerable<string> a
Assert.Equal(expected, actualFileNames);
}

public virtual string FindBinFrameworkDir(string config, bool forPublish, string framework, string? bundleDirName = null)
public virtual string FindBinFrameworkDir(string config, bool forPublish, string framework, string? bundleDirName = null, string? projectDir = null)
{
EnsureProjectDirIsSet();
string basePath = Path.Combine(ProjectDir!, "bin", config, framework);
string basePath = Path.Combine(projectDir ?? ProjectDir!, "bin", config, framework);
if (forPublish)
basePath = FindSubDirIgnoringCase(basePath, "publish");

Expand Down
Loading