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

All WasmBuildTests use static project from assets or dotnet new, unification of browser tests #109069

Merged
merged 109 commits into from
Dec 12, 2024

Conversation

ilonatommy
Copy link
Member

@ilonatommy ilonatommy commented Oct 21, 2024

Main refactoring changes:

Creation of app

old - Create the information about the requested project (BuildArgs) and using an Action that was passed to BuildProject, update the project that was hardcoded and used "data/test-main-7.0.js" or "test-main.js"

InitProject: () => File.WriteAllText(Path.Combine(_projectDir!, "Program.cs"), s_mainReturns42),

new:

  • Copy an application prepared for testing multiple scenarios, WasmBasicTestApp or BlazorBasicTestApp by using CopyTestAsset method. It is more reliable than test-main.js and faster than using dotnet new inside of the test.
  • Use dotnet new {templateName} command triggered by CreateWasmTemplateProject and return object that contains information about the created project. All the editions to the template are explicitly done in the test by replacement methods, either default replacement UpdateBrowserMainJs() / UpdateBrowserProgramFile() or custom replacements: UpdateFile(). Big snippets of code were moved to testassets to shorten test files. We either File.Copy() them or ReplaceFile() with them.
ProjectInfo info = CopyTestAsset(config, aot, "WasmBasicTestApp", prefix, "App", extraProperties: extraProperties);
ProjectInfo info = CreateWasmTemplateProject(Template.WasmBrowser, config, aot, prefix, extraProperties: extraProperties);

Building the app:

old - merged with application creation step. Used BuildProjectOptions or BlazorBuildOptions.

 BuildProject(buildArgs,
                            id: id,
                            new BuildProjectOptions(
                                InitProject: () => File.WriteAllText(Path.Combine(_projectDir!, "Program.cs"), programText),
                                DotnetWasmFromRuntimePack: dotnetWasmFromRuntimePack,
                                GlobalizationMode: GlobalizationMode.Hybrid));

new - doing only build or publish, depending if we use BuildProject or PublishProject (BlazorBuild, BlazorPublish). GetExpectedFileType is recognized automatically based on the info passed to build/publish options.

BuildTemplateProject(info,
                        new BuildProjectOptions(
                            config,
                            info.ProjectName,
                            GlobalizationMode: GlobalizationMode.Hybrid
                        ));

Running the app:

old - browser app using RunAndTestWasmApp that bases on starting a System.Diagnostics.Process in RunProcessAsync, different way of handling messages, passing arguments etc. Blazor app using Playwright in BrowserRunner.

new - both apps use Playwright (see: BrowserRunner) and the running logic is mostly common. They use either RunForBuildWithDotnetRun or RunForPublishWithWebServer in wasm and blazor apps.

Other bigger changes:

  • Avoid testing AOT + Debug unless we're checking if it fails properly - it got blocked in [wasm] Disallow not useful configuration combinations #104149 and since on CI we typically skip debug, there is a lot of test that fail when run locally but it's not a bug.
  • Tests that use old way of project creation use also old RunHost that supports testing with V8 on CI. We can remove it and replace with RunHost (DotnetRun / WebServer), used till this point only by Blazor tests.
  • Unification of records - AssertOptions, BuildOptions, moving records/enums to separate classes in Common dir etc.
  • Removal of:
  • BlazorWasmProjectProvider - when we have only bowser-sdk-based tests, we don't need multiple providers. The base provider will be removed as well.
  • TestMainJsProjectProvider - same as above, it was for wasm console tests.
  • TestMainJsTestBase - removal + edition of all the tests that were using it (16 files).
  • Blazor tests if they are not Blazor-specific, e.g. ICU tests check behavior of browser sdk code that is shared for both apps.
  • Tests that were testing if test-main.js file works correctly: ConfigSrcTests.cs.
  • Adding "TestOutput ->" to strings we want to check in the test forces recompilation of native lib native-lib.o
  • Moving constant code snippets to TestAssetsPath
  • Moving DefaultTemplate_WithoutWorkload from BuildPublishTests to WorkloadRequiredTests.

@ilonatommy ilonatommy added arch-wasm WebAssembly architecture test-enhancement Improvements of test source code area-Build-mono labels Oct 21, 2024
@ilonatommy ilonatommy self-assigned this Oct 21, 2024
@ilonatommy
Copy link
Member Author

ilonatommy commented Dec 3, 2024

New recap of the current state:

  • OptimizationFlagChangeTests - AOT=true is expected to print
    mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_AOT, "Found statically linked AOT module '%s'.", aot_name);
    message in the console. Even after setting "MONO_LOG_LEVEL", "debug" and "MONO_LOG_MASK", "aot" there's no message. We have error WasmBasicTestApp stderr instead which might be connected. No other message from runtime is redirected to the console. Fix: Setting the logging has to be done on JS side https://github.com/dotnet/runtime/blob/main/src/mono/wasm/features.md#L369
  • SimpleSourceChangeRebuildTest - AOT=true expects dotnet.native.wasm, dotnet.native.js to be changed after rebuild and they don't even exist before it. WasmBasicTestApp.dll.bc, WasmBasicTestApp.dll.o are expected to be changed but they are not. Fix: Passing AOT fixed it.
  • ReferenceNewAssemblyRebuildTest - AOT=true expects driver-gen.c to be changed and it's not. it's not because our static project already contained the "new assembly" (System.Text.Json) and the change is not visible. Fix: We have to start using a different assembly in this test.
  • PropertiesFromRuntimeConfigJson, PropertiesFromCsproj - build property is passed to binlog and set in WasmBasicTestApp.runtimeconfig.json correctly. WasmBasicTestApp.runtimeconfig.json is not listed in Network tab in the browser. Reading it in C# (AppContext.GetData()) does not work, either. Fix: failure is expected, see the comment below
  • Wasm.Build.Tests.Blazor on Linux e.g. log
 Standard Output:
      [] �]9;4;3;�\�[?25l�[1F
      []   BlazorBasicTestApp �[120G�[71DNETStandardCompatError_Microsoft_Extensions_Configuration_Binder (0.0s)
      [] �[?25h�[2F
      [] �[J�]9;4;0;�\fail: Microsoft.Extensions.Hosting.Internal.Host[11]
      []       Hosting failed to start
      []       System.IO.IOException: Failed to bind to address http://127.0.0.1:5000: address already in use.
      []        ---> Microsoft.AspNetCore.Connections.AddressInUseException: Address already in use
      []        ---> System.Net.Sockets.SocketException (98): Address already in use
      []          at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
      []          at System.Net.Sockets.Socket.Bind(EndPoint localEP)
      []          at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportOptions.CreateDefaultBoundListenSocket(EndPoint endpoint)
      []          at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.Bind()
      []          --- End of inner exception stack trace ---
      []          at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.Bind()
      []          at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportFactory.BindAsync(EndPoint endpoint, CancellationToken cancellationToken)
      []          at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.TransportManager.BindAsync(EndPoint endPoint, ConnectionDelegate connectionDelegate, EndpointConfig endpointConfig, CancellationToken cancellationToken)
      []          at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.<>c__DisplayClass28_0`1.<<StartAsync>g__OnBind|0>d.MoveNext()
      []       --- End of stack trace from previous location ---
  • Wasm.Build.Tests.Blazor.MiscTests3 (Windows) - it fails only on CI, with
C:\helix\work\workitem\e\dotnet-latest\sdk\10.0.100-alpha.1.24480.5\Microsoft.Common.CurrentVersion.targets(2413,5): error MSB3106: Assembly strong name "C:\helix\work\workitem\e\wbt artifacts\nuget\blz_dllimp_Release_鿀蜒枛遫䡫煉build_then_publish_Release_False_kcvpwszx_rwq_鿀蜒枛遫䡫煉\microsoft.extensions.dependencyinjection.abstractions\9.0.0-rc.1.24412.13\lib\net9.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll" is either a path which could not be found or it is a full assembly name which is badly formed. If it is a full assembly name it may contain characters that need to be escaped with backslash(\). Those characters are Equals(=), Comma(,), Quote("), Apostrophe('), Backslash(\). [C:\helix\work\workitem\e\wbt artifacts\blz_dllimp_Release_鿀蜒枛遫䡫煉build_then_publish_Release_False_kcvpwszx_rwq_鿀蜒枛遫䡫煉\App\BlazorBasicTestApp.csproj]
[] C:\helix\work\workitem\e\wbt artifacts\blz_dllimp_Release_鿀蜒枛遫䡫煉build_then_publish_Release_False_kcvpwszx_rwq_鿀蜒枛遫䡫煉\App\Program.cs(9,9): error CS0012: The type 'IServiceCollection' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. [C:\helix\work\workitem\e\wbt artifacts\blz_dllimp_Release_鿀蜒枛遫䡫煉build_then_publish_Release_False_kcvpwszx_rwq_鿀蜒枛遫䡫煉\App\BlazorBasicTestApp.csproj]

I disabled it in #110482. It's an issue that surfaced after refactoring.

@maraf
Copy link
Member

maraf commented Dec 4, 2024

  • PropertiesFromRuntimeConfigJson, PropertiesFromCsproj - build property is passed to binlog and set in WasmBasicTestApp.runtimeconfig.json correctly. WasmBasicTestApp.runtimeconfig.json is not listed in Network tab in the browser. Reading it in C# (AppContext.GetData()) does not work, either.

Runtime config is not passed to "runtime" (in the browser) for Wasm SDK based apps. We have a tracking issue to pass at least AppContext switch through boot config #97449

Copy link
Member

@maraf maraf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

@ilonatommy ilonatommy merged commit f30cfc0 into dotnet:main Dec 12, 2024
25 checks passed
hez2010 pushed a commit to hez2010/runtime that referenced this pull request Dec 14, 2024
…unification of browser tests (dotnet#109069)

* Fix build errors in WASI - refactor of WASI in a future PR.

* Fix binlog location.

* Update README.

* Feedback: non-nullable _projectDir.

* Fix `SatelliteAssembliesTests` and other test that require 3 states of `WasmBuildNative`

* `RebuildTests` fix after introducing figerprinting.

* Fix no-worklod tests: 1) do not double-assert `AssertRuntimePackPath` in blazor 2) `AssertRuntimePackPath` is correct  only when workload is there 3) NativeBuild should allow undefined in blazor tests as well.

* Fix `NativeBuildTests` - AppBundle was not asserted here originally.

* `WasmGenerateAppBundle=false` when workloads used (set in workload manifest). The check is incorrect in the current process of testing.

* Fix `MainWithArgsTests`. Url query can have arg key duplicates -> is better represented by `NameValueCollection` than `Dictionary`

* AppBundle was never asserted for size in `OptimizationFlagChangeTests` + use statistics that are fingerprinting insensitive.

* Reading from config is a known issue.

* Fix `ReferenceNewAssemblyRebuildTest`: Json lib was already referenced before the change in the test. Use Cryptography lib instead.

* Keep blazor workload tests together.

* Fix: `PInvokeTableGeneratorTests` on Windows.

* Move all no-workload blazor tests to one class.

* Use more meaningful name for `MiscTests3`.

* `PInvokeTableGeneratorTests` takes 2-3 times more time than average WBT class, divide it.

* Block the timeouting test with exisiting issue.

* Try avoiding port collisions in blazor tests run on kestrel.

* Removal of files and comments that were supposed to be deleted after approval.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm WebAssembly architecture area-Build-mono test-enhancement Improvements of test source code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants