Skip to content

Commit

Permalink
Fix some flaky integration tests (#2838)
Browse files Browse the repository at this point in the history
Add usings to avoid resource contention.

Co-authored-by: Remco Lam <[email protected]>
  • Loading branch information
remcolam and Remco Lam authored Apr 25, 2024
1 parent 5b62825 commit 3416927
Showing 1 changed file with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public async Task SwaggerEndpoint_ReturnsValidSwaggerJson(
string swaggerRequestUri)
{
var testSite = new TestSite(startupType);
var client = testSite.BuildClient();
using var client = testSite.BuildClient();

var swaggerResponse = await client.GetAsync(swaggerRequestUri);
using var swaggerResponse = await client.GetAsync(swaggerRequestUri);

swaggerResponse.EnsureSuccessStatusCode();
var contentStream = await swaggerResponse.Content.ReadAsStreamAsync();
using var contentStream = await swaggerResponse.Content.ReadAsStreamAsync();
new OpenApiStreamReader().Read(contentStream, out OpenApiDiagnostic diagnostic);
Assert.Empty(diagnostic.Errors);
}
Expand All @@ -45,9 +45,9 @@ public async Task SwaggerEndpoint_ReturnsValidSwaggerJson(
public async Task SwaggerEndpoint_ReturnsNotFound_IfUnknownSwaggerDocument()
{
var testSite = new TestSite(typeof(Basic.Startup));
var client = testSite.BuildClient();
using var client = testSite.BuildClient();

var swaggerResponse = await client.GetAsync("/swagger/v2/swagger.json");
using var swaggerResponse = await client.GetAsync("/swagger/v2/swagger.json");

Assert.Equal(System.Net.HttpStatusCode.NotFound, swaggerResponse.StatusCode);
}
Expand All @@ -56,9 +56,9 @@ public async Task SwaggerEndpoint_ReturnsNotFound_IfUnknownSwaggerDocument()
public async Task SwaggerEndpoint_DoesNotReturnByteOrderMark()
{
var testSite = new TestSite(typeof(Basic.Startup));
var client = testSite.BuildClient();
using var client = testSite.BuildClient();

var swaggerResponse = await client.GetAsync("/swagger/v1/swagger.json");
using var swaggerResponse = await client.GetAsync("/swagger/v1/swagger.json");

swaggerResponse.EnsureSuccessStatusCode();
var contentBytes = await swaggerResponse.Content.ReadAsByteArrayAsync();
Expand All @@ -72,12 +72,12 @@ public async Task SwaggerEndpoint_DoesNotReturnByteOrderMark()
public async Task SwaggerEndpoint_ReturnsCorrectPriceExample_ForDifferentCultures(string culture)
{
var testSite = new TestSite(typeof(Basic.Startup));
var client = testSite.BuildClient();
using var client = testSite.BuildClient();

var swaggerResponse = await client.GetAsync($"/swagger/v1/swagger.json?culture={culture}");
using var swaggerResponse = await client.GetAsync($"/swagger/v1/swagger.json?culture={culture}");

swaggerResponse.EnsureSuccessStatusCode();
var contentStream = await swaggerResponse.Content.ReadAsStreamAsync();
using var contentStream = await swaggerResponse.Content.ReadAsStreamAsync();
var currentCulture = CultureInfo.CurrentCulture;
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
try
Expand All @@ -102,12 +102,12 @@ public async Task SwaggerMiddleware_CanBeConfiguredMultipleTimes(
string expectedVersionProperty,
string expectedVersionValue)
{
var client = new TestSite(typeof(Basic.Startup)).BuildClient();
using var client = new TestSite(typeof(Basic.Startup)).BuildClient();

var response = await client.GetAsync(swaggerUrl);
using var response = await client.GetAsync(swaggerUrl);

response.EnsureSuccessStatusCode();
var contentStream = await response.Content.ReadAsStreamAsync();
using var contentStream = await response.Content.ReadAsStreamAsync();

var json = await JsonSerializer.DeserializeAsync<JsonElement>(contentStream);
Assert.Equal(expectedVersionValue, json.GetProperty(expectedVersionProperty).GetString());
Expand Down

0 comments on commit 3416927

Please sign in to comment.