62 lines
2.0 KiB
C#
62 lines
2.0 KiB
C#
// Copyright (c) .NET Foundation. All rights reserved.
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using System.Xml.Linq;
|
|
using Microsoft.AspNetCore.Server.IntegrationTesting;
|
|
using Microsoft.AspNetCore.Server.IntegrationTesting.IIS;
|
|
using Microsoft.AspNetCore.Testing;
|
|
using Xunit;
|
|
|
|
namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
|
{
|
|
public static class Helpers
|
|
{
|
|
public static string GetTestWebSitePath(string name)
|
|
{
|
|
return Path.Combine(TestPathUtilities.GetSolutionRootDirectory("IISIntegration"),"test", "WebSites", name);
|
|
}
|
|
|
|
public static string GetInProcessTestSitesPath() => GetTestWebSitePath("InProcessWebSite");
|
|
|
|
public static string GetOutOfProcessTestSitesPath() => GetTestWebSitePath("OutOfProcessWebSite");
|
|
|
|
|
|
public static async Task AssertStarts(IISDeploymentResult deploymentResult, string path = "/HelloWorld")
|
|
{
|
|
var response = await deploymentResult.RetryingHttpClient.GetAsync(path);
|
|
|
|
var responseText = await response.Content.ReadAsStringAsync();
|
|
|
|
Assert.Equal("Hello World", responseText);
|
|
}
|
|
|
|
public static async Task StressLoad(HttpClient httpClient, string path, Action<HttpResponseMessage> action)
|
|
{
|
|
async Task RunRequests()
|
|
{
|
|
var connection = new HttpClient() { BaseAddress = httpClient.BaseAddress };
|
|
|
|
for (int j = 0; j < 10; j++)
|
|
{
|
|
var response = await connection.GetAsync(path);
|
|
action(response);
|
|
}
|
|
}
|
|
|
|
List<Task> tasks = new List<Task>();
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
tasks.Add(Task.Run(RunRequests));
|
|
}
|
|
|
|
await Task.WhenAll(tasks);
|
|
}
|
|
}
|
|
}
|