2021-09-28 15:47:26 +05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
|
2021-09-28 18:02:12 +05:00
|
|
|
|
namespace AsbCloudDevOperations
|
2021-09-28 15:47:26 +05:00
|
|
|
|
{
|
|
|
|
|
public class ControllerLoadTester
|
|
|
|
|
{
|
|
|
|
|
private readonly HttpClient client = new();
|
|
|
|
|
|
2021-09-30 16:41:00 +05:00
|
|
|
|
//Пример роута: "api/telemetryDataSaub/123123_";
|
|
|
|
|
|
2021-09-28 15:47:26 +05:00
|
|
|
|
public void TestControllerRoute(string route, CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
var host = "http://localhost:5000";
|
|
|
|
|
|
2021-09-29 10:26:25 +05:00
|
|
|
|
var json = JsonSerializer.Serialize(new List<TelemetryDataSaubDto>()
|
|
|
|
|
{
|
|
|
|
|
new TelemetryDataSaubDto()
|
|
|
|
|
});
|
2021-09-28 15:47:26 +05:00
|
|
|
|
|
|
|
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Start");
|
|
|
|
|
|
|
|
|
|
var tasks = new Task[100];
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < 100; i++)
|
|
|
|
|
{
|
|
|
|
|
var res = client.PostAsync(new Uri($"{host}/{route}{i}"),
|
|
|
|
|
stringContent, token);
|
|
|
|
|
|
|
|
|
|
tasks[i] = res;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Task.WaitAll(tasks, token);
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("End");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|