Skip to content

Commit

Permalink
[wasm] Change ICU WasmBuildTests to use wasmconsole and `wasmbrow…
Browse files Browse the repository at this point in the history
…ser` templates (dotnet#108271)

* Clean up icu tests (automatic mode).

* Block the failing test, mark problems with issue links.
  • Loading branch information
ilonatommy authored Sep 27, 2024
1 parent 84b7c2f commit 01aa3d9
Show file tree
Hide file tree
Showing 19 changed files with 417 additions and 266 deletions.
4 changes: 2 additions & 2 deletions src/mono/wasm/Wasm.Build.Tests/AssertWasmSdkBundleOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public record AssertWasmSdkBundleOptions(
bool IsPublish,
string TargetFramework,
string BinFrameworkDir,
string? PredefinedIcudt,
string? CustomIcuFile,
GlobalizationMode GlobalizationMode = GlobalizationMode.Sharded,
string BootJsonFileName = "blazor.boot.json",
NativeFilesType ExpectedFileType = NativeFilesType.FromRuntimePack,
Expand All @@ -25,7 +25,7 @@ public record AssertWasmSdkBundleOptions(
IsPublish: IsPublish,
TargetFramework: TargetFramework,
BinFrameworkDir: BinFrameworkDir,
PredefinedIcudt: PredefinedIcudt,
CustomIcuFile: CustomIcuFile,
GlobalizationMode: GlobalizationMode,
ExpectedFileType: ExpectedFileType,
RuntimeType: RuntimeType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public record BlazorBuildOptions
bool ExpectFingerprintOnDotnetJs = false,
RuntimeVariant RuntimeType = RuntimeVariant.SingleThreaded,
GlobalizationMode GlobalizationMode = GlobalizationMode.Sharded,
string PredefinedIcudt = "",
string CustomIcuFile = "",
bool AssertAppBundle = true,
string? BinFrameworkDir = null
);
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void AssertBundle(BlazorBuildOptions options)
TargetFramework: options.TargetFramework,
BinFrameworkDir: options.BinFrameworkDir ?? FindBinFrameworkDir(options.Config, options.IsPublish, options.TargetFramework),
GlobalizationMode: options.GlobalizationMode,
PredefinedIcudt: options.PredefinedIcudt,
CustomIcuFile: options.CustomIcuFile,
ExpectFingerprintOnDotnetJs: options.ExpectFingerprintOnDotnetJs,
ExpectedFileType: options.ExpectedFileType,
RuntimeType: options.RuntimeType,
Expand Down
12 changes: 6 additions & 6 deletions src/mono/wasm/Wasm.Build.Tests/Blazor/IcuShardingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public async Task CustomIcuFileFromRuntimePack(string config, string fileName)
id,
config,
WarnAsError: true,
GlobalizationMode: GlobalizationMode.PredefinedIcu,
PredefinedIcudt: fileName
GlobalizationMode: GlobalizationMode.Custom,
CustomIcuFile: fileName
);
AddItemsPropertiesToProject(
projectFile,
Expand Down Expand Up @@ -65,8 +65,8 @@ public void NonExistingCustomFileAssertError(string config, string fileName, boo
id,
config,
WarnAsError: false,
GlobalizationMode: GlobalizationMode.PredefinedIcu,
PredefinedIcudt: fileName
GlobalizationMode: GlobalizationMode.Custom,
CustomIcuFile: fileName
));
}
catch (XunitException ex)
Expand Down Expand Up @@ -104,8 +104,8 @@ public async Task CustomFileNotFromRuntimePackAbsolutePath(string config)
id,
config,
WarnAsError: false,
GlobalizationMode: GlobalizationMode.PredefinedIcu,
PredefinedIcudt: IcuTestsBase.CustomIcuPath
GlobalizationMode: GlobalizationMode.Custom,
CustomIcuFile: IcuTestsBase.CustomIcuPath
));
await BlazorRunForBuildWithDotnetRun(new BlazorRunOptions() { Config = config });
}
Expand Down
10 changes: 6 additions & 4 deletions src/mono/wasm/Wasm.Build.Tests/BrowserRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ public async Task<IBrowser> SpawnBrowserAsync(
string browserUrl,
bool headless = true,
int timeout = 10000,
int maxRetries = 3
int maxRetries = 3,
string language = "en-US"
) {
var url = new Uri(browserUrl);
Playwright = await Microsoft.Playwright.Playwright.CreateAsync();
// codespaces: ignore certificate error -> Microsoft.Playwright.PlaywrightException : net::ERR_CERT_AUTHORITY_INVALID
string[] chromeArgs = new[] { $"--explicitly-allowed-ports={url.Port}", "--ignore-certificate-errors" };
string[] chromeArgs = new[] { $"--explicitly-allowed-ports={url.Port}", "--ignore-certificate-errors", $"--lang={language}" };
_testOutput.WriteLine($"Launching chrome ('{s_chromePath.Value}') via playwright with args = {string.Join(',', chromeArgs)}");

int attempt = 0;
Expand Down Expand Up @@ -146,14 +147,15 @@ public async Task<IPage> RunAsync(
ToolCommand cmd,
string args,
bool headless = true,
string language = "en-US",
Action<IPage, IConsoleMessage>? onConsoleMessage = null,
Action<string>? onServerMessage = null,
Action<string>? onError = null,
Func<string, string>? modifyBrowserUrl = null)
{
var urlString = await StartServerAndGetUrlAsync(cmd, args, onServerMessage);
var browser = await SpawnBrowserAsync(urlString, headless);
var context = await browser.NewContextAsync();
var browser = await SpawnBrowserAsync(urlString, headless, language: language);
var context = await browser.NewContextAsync(new BrowserNewContextOptions { Locale = language });
return await RunAsync(context, urlString, headless, onConsoleMessage, onError, modifyBrowserUrl);
}

Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/Wasm.Build.Tests/BuildProjectOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public record BuildProjectOptions
Action? InitProject = null,
bool? DotnetWasmFromRuntimePack = null,
GlobalizationMode GlobalizationMode = GlobalizationMode.Sharded,
string? PredefinedIcudt = null,
string? CustomIcuFile = null,
bool UseCache = true,
bool ExpectSuccess = true,
bool AssertAppBundle = true,
Expand Down
5 changes: 3 additions & 2 deletions src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,9 @@ public static int Main()
public record BuildArgs(string ProjectName,
string Config,
bool AOT,
string ProjectFileContents,
string? ExtraBuildArgs);
string Id,
string? ExtraBuildArgs,
string? ProjectFileContents=null);
public record BuildProduct(string ProjectDir, string LogFile, bool Result, string BuildOutput);

public enum NativeFilesType { FromRuntimePack, Relinked, AOT };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public abstract record AssertBundleOptionsBase(
bool IsPublish,
string TargetFramework,
string BinFrameworkDir,
string? PredefinedIcudt,
string? CustomIcuFile,
string BundleDirName = "wwwroot",
GlobalizationMode GlobalizationMode = GlobalizationMode.Sharded,
string BootJsonFileName = "blazor.boot.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public record AssertTestMainJsAppBundleOptions(
bool IsPublish,
string TargetFramework,
string BinFrameworkDir,
string? PredefinedIcudt,
string? CustomIcuFile,
string ProjectName,
string MainJS,
GlobalizationMode GlobalizationMode = GlobalizationMode.Sharded,
Expand All @@ -28,7 +28,7 @@ public record AssertTestMainJsAppBundleOptions(
IsPublish: IsPublish,
TargetFramework: TargetFramework,
BinFrameworkDir: BinFrameworkDir,
PredefinedIcudt: PredefinedIcudt,
CustomIcuFile: CustomIcuFile,
GlobalizationMode: GlobalizationMode,
ExpectedFileType: ExpectedFileType,
RuntimeType: RuntimeType,
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/Wasm.Build.Tests/Common/GlobalizationMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public enum GlobalizationMode
Sharded, // chosen based on locale
Invariant, // no icu
FullIcu, // full icu data: icudt.dat is loaded
PredefinedIcu, // user set WasmIcuDataFileName/BlazorIcuDataFileName value and we are loading that file
Custom, // user set WasmIcuDataFileName/BlazorIcuDataFileName value and we are loading that file
Hybrid // reduced icu, missing data is provided by platform-native functions (web api for wasm)
};
70 changes: 30 additions & 40 deletions src/mono/wasm/Wasm.Build.Tests/IcuShardingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
// 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.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
using System.Collections.Generic;

#nullable enable

Expand All @@ -17,47 +19,35 @@ public class IcuShardingTests : IcuTestsBase
public IcuShardingTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext)
: base(output, buildContext) { }

public static IEnumerable<object?[]> IcuExpectedAndMissingCustomShardTestData(bool aot, RunHost host)
=> ConfigWithAOTData(aot)
.Multiply(
new object[] { CustomIcuPath, s_customIcuTestedLocales, false },
new object[] { CustomIcuPath, s_customIcuTestedLocales, true })
.WithRunHosts(host)
.UnwrapItemsAsArrays();

public static IEnumerable<object?[]> IcuExpectedAndMissingAutomaticShardTestData(bool aot)
=> ConfigWithAOTData(aot)
.Multiply(
new object[] { "fr-FR", GetEfigsTestedLocales(SundayNames.French)},
new object[] { "ja-JP", GetCjkTestedLocales(SundayNames.Japanese) },
new object[] { "sk-SK", GetNocjkTestedLocales(SundayNames.Slovak) })
.WithRunHosts(BuildTestBase.s_hostsForOSLocaleSensitiveTests)
.UnwrapItemsAsArrays();
public static IEnumerable<object[]> IcuExpectedAndMissingCustomShardTestData(string config) =>
from templateType in templateTypes
from aot in boolOptions
from onlyPredefinedCultures in boolOptions
// isOnlyPredefinedCultures = true fails with wasmbrowser: https://github.com/dotnet/runtime/issues/108272
where !(onlyPredefinedCultures && templateType == "wasmbrowser")
select new object[] { config, templateType, aot, CustomIcuPath, s_customIcuTestedLocales, onlyPredefinedCultures };

public static IEnumerable<object[]> IcuExpectedAndMissingAutomaticShardTestData(string config)
{
var locales = new Dictionary<string, string>
{
{ "fr-FR", GetEfigsTestedLocales(SundayNames.French) },
{ "ja-JP", GetCjkTestedLocales(SundayNames.Japanese) },
{ "sk-SK", GetNocjkTestedLocales(SundayNames.Slovak) }
};
// "wasmconsole": https://github.com/dotnet/runtime/issues/82593
return from aot in boolOptions
from locale in locales
select new object[] { config, "wasmbrowser", aot, locale.Key, locale.Value };
}

[Theory]
[MemberData(nameof(IcuExpectedAndMissingCustomShardTestData), parameters: new object[] { false, RunHost.NodeJS | RunHost.Chrome })]
[MemberData(nameof(IcuExpectedAndMissingCustomShardTestData), parameters: new object[] { true, RunHost.NodeJS | RunHost.Chrome })]
public void CustomIcuShard(BuildArgs buildArgs, string shardName, string testedLocales, bool onlyPredefinedCultures, RunHost host, string id) =>
TestIcuShards(buildArgs, shardName, testedLocales, host, id, onlyPredefinedCultures);
[MemberData(nameof(IcuExpectedAndMissingCustomShardTestData), parameters: new object[] { "Release" })]
public async Task CustomIcuShard(string config, string templateType, bool aot, string customIcuPath, string customLocales, bool onlyPredefinedCultures) =>
await TestIcuShards(config, templateType, aot, customIcuPath, customLocales, GlobalizationMode.Custom, onlyPredefinedCultures);

[Theory]
[MemberData(nameof(IcuExpectedAndMissingAutomaticShardTestData), parameters: new object[] { false })]
[MemberData(nameof(IcuExpectedAndMissingAutomaticShardTestData), parameters: new object[] { true })]
public void AutomaticShardSelectionDependingOnEnvLocale(BuildArgs buildArgs, string environmentLocale, string testedLocales, RunHost host, string id)
{
string projectName = $"automatic_shard_{environmentLocale}_{buildArgs.Config}_{buildArgs.AOT}";
bool dotnetWasmFromRuntimePack = !(buildArgs.AOT || buildArgs.Config == "Release");

buildArgs = buildArgs with { ProjectName = projectName };
buildArgs = ExpandBuildArgs(buildArgs);

string programText = GetProgramText(testedLocales);
_testOutput.WriteLine($"----- Program: -----{Environment.NewLine}{programText}{Environment.NewLine}-------");
(_, string output) = BuildProject(buildArgs,
id: id,
new BuildProjectOptions(
InitProject: () => File.WriteAllText(Path.Combine(_projectDir!, "Program.cs"), programText),
DotnetWasmFromRuntimePack: dotnetWasmFromRuntimePack));
string runOutput = RunAndTestWasmApp(buildArgs, buildDir: _projectDir, expectedExitCode: 42, host: host, id: id, environmentLocale: environmentLocale);
}
[MemberData(nameof(IcuExpectedAndMissingAutomaticShardTestData), parameters: new object[] { "Release" })]
public async Task AutomaticShardSelectionDependingOnEnvLocale(string config, string templateType, bool aot, string environmentLocale, string testedLocales) =>
await BuildAndRunIcuTest(config, templateType, aot, testedLocales, GlobalizationMode.Sharded, language: environmentLocale);
}
36 changes: 21 additions & 15 deletions src/mono/wasm/Wasm.Build.Tests/IcuShardingTests2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
Expand All @@ -17,23 +19,27 @@ public class IcuShardingTests2 : IcuTestsBase
public IcuShardingTests2(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext)
: base(output, buildContext) { }

public static IEnumerable<object?[]> IcuExpectedAndMissingShardFromRuntimePackTestData(bool aot, RunHost host)
=> ConfigWithAOTData(aot)
.Multiply(
new object[] { "icudt.dat",
$@"new Locale[] {{
public static IEnumerable<object[]> IcuExpectedAndMissingShardFromRuntimePackTestData(string config)
{
var locales = new Dictionary<string, string>
{
{ "icudt.dat", $@"new Locale[] {{
new Locale(""en-GB"", ""{SundayNames.English}""), new Locale(""zh-CN"", ""{SundayNames.Chinese}""), new Locale(""sk-SK"", ""{SundayNames.Slovak}""),
new Locale(""xx-yy"", null) }}" },
new object[] { "icudt_EFIGS.dat", GetEfigsTestedLocales() },
new object[] { "icudt_CJK.dat", GetCjkTestedLocales() },
new object[] { "icudt_no_CJK.dat", GetNocjkTestedLocales() })
.WithRunHosts(host)
.UnwrapItemsAsArrays();

{ "icudt_EFIGS.dat", GetEfigsTestedLocales() },
{ "icudt_CJK.dat", GetCjkTestedLocales() },
{ "icudt_no_CJK.dat", GetNocjkTestedLocales() }
};
return
// "wasmconsole": https://github.com/dotnet/runtime/issues/82593
// from templateType in templateTypes
from aot in boolOptions
from locale in locales
select new object[] { config, "wasmbrowser", aot, locale.Key, locale.Value };
}

[Theory]
[MemberData(nameof(IcuExpectedAndMissingShardFromRuntimePackTestData), parameters: new object[] { false, RunHost.NodeJS | RunHost.Chrome })]
[MemberData(nameof(IcuExpectedAndMissingShardFromRuntimePackTestData), parameters: new object[] { true, RunHost.NodeJS | RunHost.Chrome })]
public void DefaultAvailableIcuShardsFromRuntimePack(BuildArgs buildArgs, string shardName, string testedLocales, RunHost host, string id) =>
TestIcuShards(buildArgs, shardName, testedLocales, host, id);
[MemberData(nameof(IcuExpectedAndMissingShardFromRuntimePackTestData), parameters: new object[] { "Release" })]
public async Task DefaultAvailableIcuShardsFromRuntimePack(string config, string templateType, bool aot, string shardName, string testedLocales) =>
await TestIcuShards(config, templateType, aot, shardName, testedLocales, GlobalizationMode.Custom);
}
Loading

0 comments on commit 01aa3d9

Please sign in to comment.