Repository: dotnet/runtime
File: src/mono/wasm/Wasm.Build.Tests/Blazor/EventPipeDiagnosticsTests.cs (C#)

Code before:
        foreach (var expectedInstrument in expectedInstruments)
        {
            Assert.True(actualInstruments.ContainsKey(expectedInstrument), $"The metrics.nettrace should contain instrument: {expectedInstrument}");
        }
    }

    [Fact]
    public async Task BlazorEventPipeTestWithHeapDump()
    {
        string extraProperties = @"
                <EnableDiagnostics>true</EnableDiagnostics>
                <WBTDevServer>true</WBTDevServer>
            ";

        ProjectInfo info = CopyTestAsset(Configuration.Release, aot: false, TestAsset.BlazorBasicTestApp, "blazor_gc_dump", extraProperties: extraProperties);

        UpdateCounterPage();

        // Build the project
        BuildProject(info, Configuration.Release, new BuildOptions(AssertAppBundle: false));

        // Create a custom test handler that will navigate to Counter page, collect CPU samples,
        // click the button, and upload the trace
        async Task CpuProfileTest(IPage page)
        {
            await SetupCounterPage(page, "gcdump.nettrace", "globalThis.getDotnetRuntime(0).collectGcDump({ durationSeconds: 5.0, skipDownload: true })");
            await ClickAndCollect(page);
        }

        // Run the test using the custom handler
        await RunForBuildWithDotnetRun(new BlazorRunOptions(
            Configuration: Configuration.Release,
            Test: CpuProfileTest,
            TimeoutSeconds: 60,
            CheckCounter: false,
            ServerEnvironment: new Dictionary<string, string>
            {
                ["DEVSERVER_UPLOAD_PATH"] = info.LogPath,
                ["DEVSERVER_UPLOAD_PATTERN"] = uploadPattern
            }
        ));

        var actualEvents = ExtractEventNames(info, "gcdump.nettrace");
        var expectedEvents = new[]
        {
            "Microsoft-Windows-DotNETRuntime/GC/Start",
            "Microsoft-Windows-DotNETRuntime/GC/Stop",
            "Microsoft-Windows-DotNETRuntime/GC/BulkEdge",
            "Microsoft-Windows-DotNETRuntime/GC/BulkNode",
            "Microsoft-Windows-DotNETRuntime/GC/BulkRootEdge",
            "Microsoft-Windows-DotNETRuntime/Type/BulkType"

Review comment (suggestion):
The local function name 'CpuProfileTest' is misleading in the context of BlazorEventPipeTestWithHeapDump, which collects a GC dump rather than CPU profiles. Consider renaming to 'HeapDumpTest' or 'CollectHeapDumpTest' for clarity.

Code after:
            Assert.True(actualInstruments.ContainsKey(expectedInstrument), $"The metrics.nettrace should contain instrument: {expectedInstrument}");
        }
    }

    [Fact]
    public async Task BlazorEventPipeTestWithHeapDump()
    {
        string extraProperties = @"
                <EnableDiagnostics>true</EnableDiagnostics>
                <WBTDevServer>true</WBTDevServer>
            ";

        ProjectInfo info = CopyTestAsset(Configuration.Release, aot: false, TestAsset.BlazorBasicTestApp, "blazor_gc_dump", extraProperties: extraProperties);

        UpdateCounterPage();

        // Build the project
        BuildProject(info, Configuration.Release, new BuildOptions(AssertAppBundle: false));

        // Create a custom test handler that will navigate to Counter page, collect CPU samples,
        // click the button, and upload the trace
        async Task CollectGcDumpTest(IPage page)
        {
            await SetupCounterPage(page, "gcdump.nettrace", "globalThis.getDotnetRuntime(0).collectGcDump({ durationSeconds: 5.0, skipDownload: true })");
            await ClickAndCollect(page);
        }

        // Run the test using the custom handler
        await RunForBuildWithDotnetRun(new BlazorRunOptions(
            Configuration: Configuration.Release,
            Test: CollectGcDumpTest,
            TimeoutSeconds: 60,
            CheckCounter: false,
            ServerEnvironment: new Dictionary<string, string>
            {
                ["DEVSERVER_UPLOAD_PATH"] = info.LogPath,
                ["DEVSERVER_UPLOAD_PATTERN"] = uploadPattern
            }
        ));

        var actualEvents = ExtractEventNames(info, "gcdump.nettrace");
        var expectedEvents = new[]
        {
            "Microsoft-Windows-DotNETRuntime/GC/Start",
            "Microsoft-Windows-DotNETRuntime/GC/Stop",
            "Microsoft-Windows-DotNETRuntime/GC/BulkEdge",
            "Microsoft-Windows-DotNETRuntime/GC/BulkNode",
            "Microsoft-Windows-DotNETRuntime/GC/BulkRootEdge",
            "Microsoft-Windows-DotNETRuntime/Type/BulkType"
        };