未验证 提交 45fd04f6 编写于 作者: P Pavel Savara 提交者: GitHub

test retry logic (#82722)

上级 cd66437f
......@@ -17,4 +17,7 @@
<NativeFileReference Include="fibonacci.c" />
<TrimmerRootDescriptor Include="$(MSBuildThisFileDirectory)ILLink.Descriptors.xml" />
</ItemGroup>
<Target Name="RunSample" DependsOnTargets="RunSampleWithBrowserAndSimpleServer" />
</Project>
......@@ -7,6 +7,9 @@ function add(a, b) {
return a + b;
}
let testAbort = true;
let testError = true;
try {
const { runtimeBuildInfo, setModuleImports, getAssemblyExports, runMain, getConfig, Module } = await dotnet
.withElementOnExit()
......@@ -22,6 +25,21 @@ try {
config.environmentVariables["MONO_LOG_LEVEL"] = "debug";
config.browserProfilerOptions = {};
},
imports: {
fetch: (url, fetchArgs) => {
console.log("fetching " + url);
// we are testing that we can retry loading of the assembly
if (testAbort && url.indexOf('System.Private.Uri.dll') != -1) {
testAbort = false;
return fetch(url + "?testAbort=true", fetchArgs);
}
if (testError && url.indexOf('System.Console.dll') != -1) {
testError = false;
return fetch(url + "?testError=true", fetchArgs);
}
return fetch(url, fetchArgs);
}
},
preInit: () => { console.log('user code Module.preInit'); },
preRun: () => { console.log('user code Module.preRun'); },
onRuntimeInitialized: () => {
......
......@@ -156,19 +156,43 @@ private async void ServeAsync(HttpListenerContext context)
string? contentType = null;
if (path.EndsWith(".wasm"))
contentType = "application/wasm";
if (path.EndsWith(".webcil"))
if (path.EndsWith(".webcil") || path.EndsWith(".dll") || path.EndsWith(".pdb"))
contentType = "application/octet-stream";
if (path.EndsWith(".json"))
contentType = "application/json";
if (path.EndsWith(".js") || path.EndsWith(".mjs") || path.EndsWith(".cjs"))
contentType = "text/javascript";
var stream = context.Response.OutputStream;
// test download re-try
if (url.Query.Contains("testError"))
{
Console.WriteLine("Faking 500 " + url);
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
await stream.WriteAsync(buffer, 0, 0).ConfigureAwait(false);
await stream.FlushAsync();
context.Response.Close();
return;
}
if (contentType != null)
context.Response.ContentType = contentType;
context.Response.ContentLength64 = buffer.Length;
context.Response.AppendHeader("cache-control", "public, max-age=31536000");
var stream = context.Response.OutputStream;
// test download re-try
if (url.Query.Contains("testAbort"))
{
Console.WriteLine("Faking abort " + url);
await stream.WriteAsync(buffer, 0, 10).ConfigureAwait(false);
await stream.FlushAsync();
await Task.Delay(100);
context.Response.Abort();
return;
}
try
{
await stream.WriteAsync(buffer).ConfigureAwait(false);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册