From 1ff5f3b6c88a6333519c562f3bbc1f29e79b111b Mon Sep 17 00:00:00 2001 From: KharchenkoVV Date: Fri, 1 Oct 2021 15:27:54 +0500 Subject: [PATCH] Added telemetry info and data saub requests to ControllersLoadTester.cs --- AsbCloudDbDemoData/ControllerLoadTester.cs | 47 +++++++++++++++------- AsbCloudDbDemoData/Program.cs | 2 +- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/AsbCloudDbDemoData/ControllerLoadTester.cs b/AsbCloudDbDemoData/ControllerLoadTester.cs index 8f8e63b1..7eccf6bd 100644 --- a/AsbCloudDbDemoData/ControllerLoadTester.cs +++ b/AsbCloudDbDemoData/ControllerLoadTester.cs @@ -12,35 +12,52 @@ namespace AsbCloudDevOperations public class ControllerLoadTester { private readonly HttpClient client = new(); + private readonly Random rand = new(); //Пример роута: "api/telemetryDataSaub/123123_"; - public void TestControllerRoute(string route, CancellationToken token = default) - { - var host = "http://localhost:5000"; + public void TestControllerRoute(CancellationToken token = default) + { + var tasks = new List(); + + 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() { new TelemetryDataSaubDto() }); - var stringContent = new StringContent(json, Encoding.UTF8, "application/json"); + var stringContent = new StringContent(json, Encoding.UTF8, + "application/json"); - Console.WriteLine("Start"); + var uid = $"123123_1"; - var tasks = new Task[100]; + Console.WriteLine($"Sending telemetry info with uid: {uid}"); - for (var i = 0; i < 100; i++) + 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++) { - var res = client.PostAsync(new Uri($"{host}/{route}{i}"), - stringContent, token); + 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); - tasks[i] = res; - }; - - Task.WaitAll(tasks, token); - - Console.WriteLine("End"); + Console.WriteLine(saubResponse.StatusCode); + } } } } diff --git a/AsbCloudDbDemoData/Program.cs b/AsbCloudDbDemoData/Program.cs index 6ccb1083..60281018 100644 --- a/AsbCloudDbDemoData/Program.cs +++ b/AsbCloudDbDemoData/Program.cs @@ -12,7 +12,7 @@ namespace AsbCloudDevOperations { var controllerTester = new ControllerLoadTester(); - controllerTester.TestControllerRoute("api/telemetryDataSaub/123123_"); + controllerTester.TestControllerRoute(); //.GetAwaiter().GetResult(); Console.WriteLine("End of Test");