forked from ddrilling/AsbCloudServer
64 lines
1.9 KiB
C#
64 lines
1.9 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 AsbCloudDevOperations
|
||
{
|
||
public class ControllerLoadTester
|
||
{
|
||
private readonly HttpClient client = new();
|
||
private readonly Random rand = new();
|
||
|
||
//Пример роута: "api/telemetryDataSaub/123123_";
|
||
|
||
|
||
public void TestControllerRoute(CancellationToken token = default)
|
||
{
|
||
var tasks = new List<Task>();
|
||
|
||
for (var i = 0; i < 30; i++)
|
||
{
|
||
tasks.Add(SendRequestsAsync(i, token));
|
||
};
|
||
|
||
Task.WaitAll(tasks.ToArray(), token);
|
||
|
||
Console.WriteLine("End");
|
||
}
|
||
|
||
private async Task SendRequestsAsync(int i, CancellationToken token)
|
||
{
|
||
var json = JsonSerializer.Serialize(new List<TelemetryDataSaubDto>()
|
||
{
|
||
new TelemetryDataSaubDto()
|
||
});
|
||
|
||
var stringContent = new StringContent(json, Encoding.UTF8,
|
||
"application/json");
|
||
|
||
var uid = $"123123_1";
|
||
|
||
Console.WriteLine($"Sending telemetry info with uid: {uid}");
|
||
|
||
var tInfoUri = new Uri($"http://localhost:5000/api/telemetry/{uid}/info");
|
||
var infoResponse = await client.PostAsync(tInfoUri, stringContent, token);
|
||
|
||
Console.WriteLine($"Передана telemetry info с: {infoResponse.StatusCode}");
|
||
|
||
for (var j = 0; j <= 10; j++)
|
||
{
|
||
await Task.Delay(rand.Next(1000, 5000), token);
|
||
var dataSaubUri = new Uri($"http://localhost:5000/api/telemetryDataSaub/{uid}");
|
||
var saubResponse = await client.PostAsync(dataSaubUri, stringContent, token);
|
||
|
||
Console.WriteLine(saubResponse.StatusCode);
|
||
}
|
||
}
|
||
}
|
||
}
|