DD.WellWorkover.Cloud/AsbCloudDbDemoData/ControllerLoadTester.cs
2021-09-28 15:47:26 +05:00

42 lines
1.0 KiB
C#

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;
namespace AsbCloudDbDemoData
{
public class ControllerLoadTester
{
private readonly HttpClient client = new();
public void TestControllerRoute(string route, CancellationToken token = default)
{
var host = "http://localhost:5000";
var json = JsonSerializer.Serialize(new List<TelemetryDataSaubDto>());
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");
}
}
}