1
0
Fork 0
mirror of https://github.com/VSadov/Satori.git synced 2025-06-10 01:50:53 +09:00

[browser] Add test case for maxParallelDownloads (#104476)

This commit is contained in:
Ilona Tomkowicz 2024-07-08 09:55:19 +00:00 committed by GitHub
parent e71e0f4f84
commit 27d1ab0393
Signed by: github
GPG key ID: B5690EEEBB952194
2 changed files with 69 additions and 0 deletions

View file

@ -0,0 +1,48 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit.Abstractions;
using System.Text.RegularExpressions;
using Xunit;
#nullable enable
namespace Wasm.Build.Tests.TestAppScenarios;
public class MaxParallelDownloadsTests : AppTestBase
{
public MaxParallelDownloadsTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext)
: base(output, buildContext)
{
}
[Theory]
[InlineData("Release", "1")]
[InlineData("Release", "4")]
public async Task NeverFetchMoreThanMaxAllowed(string config, string maxParallelDownloads)
{
CopyTestAsset("WasmBasicTestApp", "MaxParallelDownloadsTests", "App");
BuildProject(config);
var result = await RunSdkStyleAppForBuild(new(
Configuration: config,
TestScenario: "MaxParallelDownloads",
BrowserQueryString: new Dictionary<string, string> { ["maxParallelDownloads"] = maxParallelDownloads }
));
var resultTestOutput = result.TestOutput.ToList();
var regex = new Regex(@"Active downloads: (\d+)");
foreach (var line in resultTestOutput)
{
var match = regex.Match(line);
if (match.Success)
{
int activeDownloads = int.Parse(match.Groups[1].Value);
Assert.True(activeDownloads <= int.Parse(maxParallelDownloads), $"Active downloads exceeded the limit: {activeDownloads} > {maxParallelDownloads}");
}
}
}
}

View file

@ -93,6 +93,26 @@ switch (testCase) {
await dotnet.download(); await dotnet.download();
testOutput("download finished"); testOutput("download finished");
break; break;
case "MaxParallelDownloads":
const maxParallelDownloads = params.get("maxParallelDownloads");
let activeFetchCount = 0;
const originalFetch2 = globalThis.fetch;
globalThis.fetch = async (...args) => {
activeFetchCount++;
testOutput(`Fetch started. Active downloads: ${activeFetchCount}`);
try {
const response = await originalFetch2(...args);
activeFetchCount--;
testOutput(`Fetch completed. Active downloads: ${activeFetchCount}`);
return response;
} catch (error) {
activeFetchCount--;
testOutput(`Fetch failed. Active downloads: ${activeFetchCount}`);
throw error;
}
};
dotnet.withConfig({ maxParallelDownloads: maxParallelDownloads });
break;
} }
const { setModuleImports, getAssemblyExports, getConfig, INTERNAL } = await dotnet.create(); const { setModuleImports, getAssemblyExports, getConfig, INTERNAL } = await dotnet.create();
@ -145,6 +165,7 @@ try {
exit(0); exit(0);
break; break;
case "DownloadThenInit": case "DownloadThenInit":
case "MaxParallelDownloads":
exit(0); exit(0);
break; break;
default: default: