Skip to content
Merged
Show file tree
Hide file tree
Changes from 39 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 @@ -15,6 +15,7 @@ public record BlazorRunOptions
bool CheckCounter = true,
Func<IPage, Task>? Test = null,
Action<IConsoleMessage>? OnConsoleMessage = null,
Action<string>? OnServerMessage = null,
Action<string>? OnErrorMessage = null,
string Config = "Debug",
string? ExtraArgs = null,
Expand Down
18 changes: 15 additions & 3 deletions src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,13 @@ public async Task BlazorRunTest(string runArgs,
.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,
onConsoleMessage: OnConsoleMessage,
onServerMessage: runOptions.OnServerMessage,
onError: OnErrorMessage,
modifyBrowserUrl: browserUrl => browserUrl + runOptions.QueryString);

_testOutput.WriteLine("Waiting for page to load");
await page.WaitForLoadStateAsync(LoadState.DOMContentLoaded, new () { Timeout = 1 * 60 * 1000 });
Expand Down Expand Up @@ -237,6 +243,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);
}
}
13 changes: 10 additions & 3 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 @@ -106,10 +112,11 @@ public async Task<IPage> RunAsync(
string args,
bool headless = true,
Action<IConsoleMessage>? onConsoleMessage = 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);
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
74 changes: 63 additions & 11 deletions src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,48 @@ protected void CopyTestAsset(string assetName, string generatedProjectNamePrefix
LogPath = Path.Combine(s_buildEnv.LogRootPath, Id);
Utils.DirectoryCopy(Path.Combine(BuildEnvironment.TestAssetsPath, assetName), Path.Combine(_projectDir!));

// WasmBasicTestApp consists of App + Library projects
if (assetName == "WasmBasicTestApp")
_projectDir = Path.Combine(_projectDir!, "App");
switch(assetName)
{
case "WasmBasicTestApp":
// WasmBasicTestApp consists of App + Library projects
_projectDir = Path.Combine(_projectDir!, "App");
break;
case "BlazorHostedApp":
// BlazorHostedApp consists of BlazorHosted.Client and BlazorHosted.Server projects
_projectDir = Path.Combine(_projectDir!, "BlazorHosted.Server");
break;
}
}

protected void BlazorHostedBuild(
string config,
string assetName,
string clientDirRelativeToProjectDir = "",
string? generatedProjectNamePrefix = null,
RuntimeVariant runtimeType = RuntimeVariant.SingleThreaded)
{
CopyTestAsset(assetName, generatedProjectNamePrefix);
string frameworkDir = FindBlazorHostedBinFrameworkDir(config,
forPublish: false,
clientDirRelativeToProjectDir: clientDirRelativeToProjectDir);
BuildProject(configuration: config,
binFrameworkDir: frameworkDir,
runtimeType: runtimeType);
}

protected void BuildProject(string configuration, params string[] extraArgs)
protected void BuildProject(
string configuration,
string? binFrameworkDir = null,
RuntimeVariant runtimeType = RuntimeVariant.SingleThreaded,
bool assertAppBundle = true,
params string[] extraArgs)
{
(CommandResult result, _) = BlazorBuild(new BlazorBuildOptions(Id, configuration), extraArgs);
(CommandResult result, _) = BlazorBuild(new BlazorBuildOptions(
Id: Id,
Config: configuration,
BinFrameworkDir: binFrameworkDir,
RuntimeType: runtimeType,
AssertAppBundle: assertAppBundle), extraArgs);
result.EnsureSuccessful();
}

Expand All @@ -54,7 +88,7 @@ protected void PublishProject(string configuration, params string[] extraArgs)

protected Task<RunResult> RunSdkStyleAppForBuild(RunOptions options)
=> RunSdkStyleApp(options, BlazorRunHost.DotnetRun);

protected Task<RunResult> RunSdkStyleAppForPublish(RunOptions options)
=> RunSdkStyleApp(options, BlazorRunHost.WebServer);

Expand All @@ -67,12 +101,14 @@ private async Task<RunResult> RunSdkStyleApp(RunOptions options, BlazorRunHost h
var tcs = new TaskCompletionSource<int>();
List<string> testOutput = new();
List<string> consoleOutput = new();
List<string> serverOutput = new();
Regex exitRegex = new Regex("WASM EXIT (?<exitCode>[0-9]+)$");

BlazorRunOptions blazorRunOptions = new(
CheckCounter: false,
Config: options.Configuration,
OnConsoleMessage: OnConsoleMessage,
OnServerMessage: OnServerMessage,
QueryString: queryString,
Host: host);

Expand All @@ -82,9 +118,7 @@ void OnConsoleMessage(IConsoleMessage msg)
{
consoleOutput.Add(msg.Text);

const string testOutputPrefix = "TestOutput -> ";
if (msg.Text.StartsWith(testOutputPrefix))
testOutput.Add(msg.Text.Substring(testOutputPrefix.Length));
OnTestOutput(msg.Text);

var exitMatch = exitRegex.Match(msg.Text);
if (exitMatch.Success)
Expand All @@ -97,6 +131,22 @@ void OnConsoleMessage(IConsoleMessage msg)
options.OnConsoleMessage(msg);
}

void OnServerMessage(string msg)
{
serverOutput.Add(msg);
OnTestOutput(msg);

if (options.OnServerMessage != null)
options.OnServerMessage(msg);
}

void OnTestOutput(string msg)
{
const string testOutputPrefix = "TestOutput -> ";
if (msg.StartsWith(testOutputPrefix))
testOutput.Add(msg.Substring(testOutputPrefix.Length));
}

//TimeSpan timeout = TimeSpan.FromMinutes(2);
//await Task.WhenAny(tcs.Task, Task.Delay(timeout));
//if (!tcs.Task.IsCompleted)
Expand All @@ -106,20 +156,22 @@ void OnConsoleMessage(IConsoleMessage msg)
if (options.ExpectedExitCode != null && wasmExitCode != options.ExpectedExitCode)
throw new Exception($"Expected exit code {options.ExpectedExitCode} but got {wasmExitCode}");

return new(wasmExitCode, testOutput, consoleOutput);
return new(wasmExitCode, testOutput, consoleOutput, serverOutput);
}

protected record RunOptions(
string Configuration,
string TestScenario,
Dictionary<string, string> BrowserQueryString = null,
Action<IConsoleMessage> OnConsoleMessage = null,
Action<string> OnServerMessage = null,
int? ExpectedExitCode = 0
);

protected record RunResult(
int ExitCode,
IReadOnlyCollection<string> TestOutput,
IReadOnlyCollection<string> ConsoleOutput
IReadOnlyCollection<string> ConsoleOutput,
IReadOnlyCollection<string> ServerOutput
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public DebugLevelTests(ITestOutputHelper output, SharedBuildPerTestClassFixture
{
}

private void AssertDebugLevel(RunResult result, int value)
private void AssertDebugLevel(RunResult result, int value)
{
Assert.Collection(
result.TestOutput,
Expand Down Expand Up @@ -51,7 +51,7 @@ public async Task BuildWithDefaultLevel(string configuration)
public async Task BuildWithExplicitValue(string configuration, int debugLevel)
{
CopyTestAsset("WasmBasicTestApp", $"DebugLevelTests_BuildWithExplicitValue_{configuration}");
BuildProject(configuration, $"-p:WasmDebugLevel={debugLevel}");
BuildProject(configuration: configuration, extraArgs: $"-p:WasmDebugLevel={debugLevel}");

var result = await RunSdkStyleAppForBuild(new(
Configuration: configuration,
Expand Down
Loading