Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting;
/// <summary>
/// Result of a deployment.
/// </summary>
public class DeploymentResult
public class DeploymentResult : IDisposable
{
private readonly ILoggerFactory _loggerFactory;

Expand Down Expand Up @@ -67,4 +67,6 @@ public HttpClient CreateHttpClient(HttpMessageHandler baseHandler) =>
BaseAddress = new Uri(ApplicationBaseUri),
Timeout = TimeSpan.FromSeconds(200),
};

public void Dispose() => HttpClient.Dispose();
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
// 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.Globalization;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
using Xunit;
using Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing;
Expand Down Expand Up @@ -58,11 +53,11 @@ public async Task EnvVarInWebConfig_Valid(TestVariant variant)
var port = GetUnusedRandomPort();
deploymentParameters.WebConfigBasedEnvironmentVariables["ASPNETCORE_PORT"] = port.ToString(CultureInfo.InvariantCulture);

var deploymentResult = await DeployAsync(deploymentParameters);

var responseText = await deploymentResult.HttpClient.GetStringAsync("/ServerAddresses");

Assert.Equal(port, new Uri(responseText).Port);
await RunTest(deploymentParameters, async deploymentResult =>
{
var responseText = await deploymentResult.HttpClient.GetStringAsync("/ServerAddresses");
Assert.Equal(port, new Uri(responseText).Port);
});
}

[ConditionalTheory]
Expand All @@ -73,12 +68,13 @@ public async Task EnvVarInWebConfig_Empty(TestVariant variant)
var deploymentParameters = Fixture.GetBaseDeploymentParameters(variant);
deploymentParameters.WebConfigBasedEnvironmentVariables["ASPNETCORE_PORT"] = string.Empty;

var deploymentResult = await DeployAsync(deploymentParameters);

var responseText = await deploymentResult.HttpClient.GetStringAsync("/ServerAddresses");
await RunTest(deploymentParameters, async deploymentResult =>
{
var responseText = await deploymentResult.HttpClient.GetStringAsync("/ServerAddresses");

// If env var is empty, ANCM should assign a random port (same as no env var)
Assert.InRange(new Uri(responseText).Port, _minPort, _maxPort);
// If env var is empty, ANCM should assign a random port (same as no env var)
Assert.InRange(new Uri(responseText).Port, _minPort, _maxPort);
});
}

[ConditionalTheory]
Expand All @@ -89,11 +85,11 @@ public async Task EnvVarInWebConfig_Invalid(TestVariant variant, string port)
var deploymentParameters = Fixture.GetBaseDeploymentParameters(variant);
deploymentParameters.WebConfigBasedEnvironmentVariables["ASPNETCORE_PORT"] = port;

var deploymentResult = await DeployAsync(deploymentParameters);

var response = await deploymentResult.HttpClient.GetAsync("/ServerAddresses");

Assert.Equal(HttpStatusCode.BadGateway, response.StatusCode);
await RunTest(deploymentParameters, async deploymentResult =>
{
var response = await deploymentResult.HttpClient.GetAsync("/ServerAddresses");
Assert.Equal(HttpStatusCode.BadGateway, response.StatusCode);
});
}

[ConditionalTheory]
Expand All @@ -104,45 +100,46 @@ public async Task ShutdownMultipleTimesWorks(TestVariant variant)
// Must publish to set env vars in web.config
var deploymentParameters = Fixture.GetBaseDeploymentParameters(variant);

var deploymentResult = await DeployAsync(deploymentParameters);

// Shutdown once
var response = await deploymentResult.HttpClient.GetAsync("/Shutdown");

// Wait for server to start again.
int i;
for (i = 0; i < 10; i++)
await RunTest(deploymentParameters, async deploymentResult =>
{
// ANCM should eventually recover from being shutdown multiple times.
response = await deploymentResult.HttpClient.GetAsync("/HelloWorld");
if (response.IsSuccessStatusCode)
// Shutdown once
var response = await deploymentResult.HttpClient.GetAsync("/Shutdown");

// Wait for server to start again.
int i;
for (i = 0; i < 10; i++)
{
break;
// ANCM should eventually recover from being shutdown multiple times.
response = await deploymentResult.HttpClient.GetAsync("/HelloWorld");
if (response.IsSuccessStatusCode)
{
break;
}
}
}

if (i == 10)
{
// Didn't restart after 10 retries
Assert.False(true);
}
if (i == 10)
{
// Didn't restart after 10 retries
Assert.False(true);
}

// Shutdown again
response = await deploymentResult.HttpClient.GetAsync("/Shutdown");
// Shutdown again
response = await deploymentResult.HttpClient.GetAsync("/Shutdown");

// return if server starts again.
for (i = 0; i < 10; i++)
{
// ANCM should eventually recover from being shutdown multiple times.
response = await deploymentResult.HttpClient.GetAsync("/HelloWorld");
if (response.IsSuccessStatusCode)
// return if server starts again.
for (i = 0; i < 10; i++)
{
return;
// ANCM should eventually recover from being shutdown multiple times.
response = await deploymentResult.HttpClient.GetAsync("/HelloWorld");
if (response.IsSuccessStatusCode)
{
return;
}
}
}

// Test failure if this happens.
Assert.False(true);
// Test failure if this happens.
Assert.False(true);
});
}

private static int GetUnusedRandomPort()
Expand Down
Loading