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); }
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 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); }