Fix GetModule_ReturnsModule test failure on browser-wasm#125286
Fix GetModule_ReturnsModule test failure on browser-wasm#125286
Conversation
The else branch added in PR #125080 assumed !HasAssemblyFiles implies NativeAOT, but browser-wasm also has !HasAssemblyFiles. On wasm (Mono), Module.Name returns the real DLL name, not "<Unknown>", so the assertion fails. Split the else branch to handle NativeAOT and wasm separately. Fixes #125245 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
There was a problem hiding this comment.
Pull request overview
Fixes a failing System.Reflection.Context test on browser-wasm by separating the previous !HasAssemblyFiles behavior into distinct expectations for NativeAOT vs wasm/other platforms, aligning assertions with runtime-specific Module.Name results.
Changes:
- Update
GetModule_ReturnsModuleto treat!HasAssemblyFilesas either NativeAOT (expect"<Unknown>") or non-NativeAOT (expectGetModule(name)succeeds). - Keep the test unconditionally runnable while branching assertions per platform behavior.
| { | ||
| // On browser-wasm, HasAssemblyFiles is false but Module.Name still returns the real name | ||
| Module module = _customAssembly.GetModule(moduleName); | ||
| Assert.NotNull(module); | ||
| } |
There was a problem hiding this comment.
In the non-NativeAOT paths, both branches do the same thing (call GetModule(moduleName) and assert not null). This can be simplified to reduce duplication (e.g., handle IsNativeAot first, otherwise always assert GetModule is non-null), and the comment should be generalized since this else applies to any !HasAssemblyFiles && !IsNativeAot, not only browser-wasm.
| else if (PlatformDetection.IsNativeAot) | ||
| { | ||
| // On native AOT, Module.Name returns "<Unknown>" and GetModule with that name returns null | ||
| Assert.Equal("<Unknown>", moduleName); |
There was a problem hiding this comment.
The comment says GetModule returns null on native AOT, but this branch only asserts moduleName is "". Either update the comment to match what’s being asserted, or add an assertion that _customAssembly.GetModule(moduleName) is null to validate the stated behavior.
| Assert.Equal("<Unknown>", moduleName); | |
| Assert.Equal("<Unknown>", moduleName); | |
| Module module = _customAssembly.GetModule(moduleName); | |
| Assert.Null(module); |
| } | ||
| else | ||
| { | ||
| // On browser-wasm, HasAssemblyFiles is false but Module.Name still returns the real name |
There was a problem hiding this comment.
Is this valid for CoreCLR as well?
There was a problem hiding this comment.
I have no idea, I'd just prefer people not commit red tests, we can revert #125080 and discuss it more
There was a problem hiding this comment.
Sure, I am just pointing out that this change is likely moving the red to a different configuration yet again.
I'd just prefer people not commit red tests, we can revert #125080 and discuss it more
The build analysis flagged this test on wasm as a known failure in #125080. The problem was that the matching pattern in #125051 that tracked the know failure was not specific enough. cc @matouskozak
There was a problem hiding this comment.
Right, I wasn't intending on merging it on red, I opened the PR to hand off to the proper owner. I'm tired of tracking down red tests that were recently added and then become my problem.
|
@danmoseley we need tests that work for all the versions of the platforms including the outerloops can you take a look please. |
|
Longer term we should have a plan for converging behavior, I.e. coreclr has a consistent behavior for these situations and I presume we will continue to use that behavior on wasm. |
|
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run runtime-extra-platforms |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Are these two outerloops everything? If they are green too we can merge this? And in terms of learnings for me, it's that before merging reflection-related test changes I should run various outerloops. For the match pattern in #125051, I'm not sure what it should have been to be more specific. |
The
elsebranch added in PR #125080 assumed!HasAssemblyFilesimplies NativeAOT, but browser-wasm also has!HasAssemblyFiles(sinceAssembly.Locationis empty). On wasm (Mono),Module.Namereturns the real DLL name ("System.Reflection.Context.Tests.dll"), not"<Unknown>", so the assertion fails.Split the
elsebranch to handle NativeAOT and wasm separately:Module.Name == "<Unknown>"GetModule(moduleName)and assert not nullFixes #125245