private static async Task WarmUpServer(AspNetProcess aspNetProcess) { var intervalInSeconds = 5; var attempt = 0; var maxAttempts = 5; var stopwatch = new Stopwatch(); stopwatch.Start(); do { try { attempt++; var response = await aspNetProcess.SendRequest("/"); if (response.StatusCode == HttpStatusCode.OK) { return; } } catch (OperationCanceledException) { } catch (HttpRequestException ex) when(ex.Message.StartsWith("The SSL connection could not be established")) { } var currentDelay = intervalInSeconds * attempt; await Task.Delay(TimeSpan.FromSeconds(currentDelay)); } while (attempt < maxAttempts); stopwatch.Stop(); throw new TimeoutException($"Could not contact the server within {stopwatch.Elapsed.TotalSeconds} seconds"); }
private static async Task WarmUpServer(AspNetProcess aspNetProcess) { var attempt = 0; var maxAttempts = 3; do { try { attempt++; var response = await aspNetProcess.SendRequest("/"); if (response.StatusCode == HttpStatusCode.OK) { break; } } catch (OperationCanceledException) { } catch (HttpRequestException ex) when(ex.Message.StartsWith("The SSL connection could not be established")) { } await Task.Delay(TimeSpan.FromSeconds(5 * attempt)); } while (attempt < maxAttempts); }
public async Task BlazorWasmStandaloneTemplate_Works() { var project = await ProjectFactory.GetOrCreateProject("blazorstandalone", Output); project.TargetFramework = "netstandard2.1"; var createResult = await project.RunDotNetNewAsync("blazorwasm"); Assert.True(0 == createResult.ExitCode, ErrorMessages.GetFailedProcessMessage("create/restore", project, createResult)); var publishResult = await project.RunDotNetPublishAsync(); Assert.True(0 == publishResult.ExitCode, ErrorMessages.GetFailedProcessMessage("publish", project, publishResult)); var buildResult = await project.RunDotNetBuildAsync(); Assert.True(0 == buildResult.ExitCode, ErrorMessages.GetFailedProcessMessage("build", project, buildResult)); await BuildAndRunTest(project.ProjectName, project); var publishDir = Path.Combine(project.TemplatePublishDir, project.ProjectName, "dist"); AspNetProcess.EnsureDevelopmentCertificates(); Output.WriteLine("Running dotnet serve on published output..."); using var serveProcess = ProcessEx.Run(Output, publishDir, DotNetMuxer.MuxerPathOrDefault(), "serve -S"); // Todo: Use dynamic port assignment: https://github.com/natemcmaster/dotnet-serve/pull/40/files var listeningUri = "https://localhost:8080"; Output.WriteLine($"Opening browser at {listeningUri}..."); Browser.Navigate().GoToUrl(listeningUri); TestBasicNavigation(project.ProjectName); }
private async Task ValidatePublishedFiles(AspNetProcess aspNetProcess, string[] expectedContentFiles) { foreach (var file in expectedContentFiles) { var response = await aspNetProcess.SendRequest(file); Assert.True(response?.StatusCode == HttpStatusCode.OK, $"Couldn't find file '{file}'"); } }
private static async Task AssertCompressionFormat(AspNetProcess aspNetProcess, string expectedEncoding) { var response = await aspNetProcess.SendRequest(() => { var request = new HttpRequestMessage(HttpMethod.Get, new Uri(aspNetProcess.ListeningUri, "/_framework/blazor.boot.json")); // These are the same as chrome request.Headers.AcceptEncoding.Clear(); request.Headers.AcceptEncoding.Add(StringWithQualityHeaderValue.Parse("gzip")); request.Headers.AcceptEncoding.Add(StringWithQualityHeaderValue.Parse("deflate")); request.Headers.AcceptEncoding.Add(StringWithQualityHeaderValue.Parse("br")); return request; }); Assert.Equal(expectedEncoding, response.Content.Headers.ContentEncoding.Single()); }
private static async Task WarmUpServer(AspNetProcess aspNetProcess) { var attempt = 0; var maxAttempts = 3; do { try { attempt++; var response = await aspNetProcess.SendRequest("/"); if (response.StatusCode == HttpStatusCode.OK) { break; } } catch (OperationCanceledException) { } await Task.Delay(TimeSpan.FromSeconds(5 * attempt)); } while (attempt < maxAttempts); }