Initial version of the load test (?)
This commit is contained in:
@@ -1,9 +1,109 @@
|
|||||||
namespace LoadTest;
|
//creare un programma che genera tante chiamate HTTP con inserimento di
|
||||||
|
//URL + eventuale Token
|
||||||
|
//Body
|
||||||
|
//Per quanto tempo fare il test
|
||||||
|
//Metodo HTTP
|
||||||
|
//Numero Thread(?)
|
||||||
|
|
||||||
class Program
|
using System.Diagnostics;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
|
||||||
|
namespace LoadTest;
|
||||||
|
|
||||||
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
private static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Hello, World!");
|
string? url = null;
|
||||||
|
string? body = null;
|
||||||
|
string? header = null;
|
||||||
|
string? token = null;
|
||||||
|
string? methodHttp = null;
|
||||||
|
string? time;
|
||||||
|
long? lTime;
|
||||||
|
string? yn;
|
||||||
|
Stopwatch sw;
|
||||||
|
|
||||||
|
Console.WriteLine("Load Test");
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Console.WriteLine("Insert Method Http (GET/POST): ");
|
||||||
|
methodHttp = Console.ReadLine();
|
||||||
|
} while (string.IsNullOrEmpty(methodHttp) && (methodHttp?.ToUpper() != "GET" || methodHttp?.ToUpper() != "POST"));
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Console.WriteLine("Insert URL: ");
|
||||||
|
url = Console.ReadLine();
|
||||||
|
url = "https://" + url;
|
||||||
|
} while (string.IsNullOrEmpty(url) && url != "https://");
|
||||||
|
|
||||||
|
if (methodHttp == "POST")
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Console.WriteLine("Insert Body: ");
|
||||||
|
body = Console.ReadLine();
|
||||||
|
} while (string.IsNullOrEmpty(body));
|
||||||
|
}
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Console.WriteLine("Is Authentication required? (Y/N)");
|
||||||
|
yn = Console.ReadLine();
|
||||||
|
} while(string.IsNullOrEmpty(yn) && (yn?.ToLower() != ConsoleKey.Y.ToString().ToLower() || yn?.ToLower() != ConsoleKey.N.ToString().ToLower()));
|
||||||
|
|
||||||
|
if (yn?.ToLower() == "y")
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Console.WriteLine("Header");
|
||||||
|
header = Console.ReadLine();
|
||||||
|
} while (string.IsNullOrEmpty(header));
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Console.WriteLine("Token: ");
|
||||||
|
token = Console.ReadLine();
|
||||||
|
} while (string.IsNullOrEmpty(token));
|
||||||
|
}
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Console.WriteLine("Insert Time in seconds: ");
|
||||||
|
time = Console.ReadLine();
|
||||||
|
|
||||||
|
} while (string.IsNullOrEmpty(time));
|
||||||
|
lTime = long.Parse(time) * 1000;
|
||||||
|
|
||||||
|
using var client = new HttpClient() ;
|
||||||
|
if (yn == "y" && !string.IsNullOrEmpty(token) && !string.IsNullOrEmpty(header))
|
||||||
|
{
|
||||||
|
client.DefaultRequestHeaders.Add(header, token);
|
||||||
|
}
|
||||||
|
switch (methodHttp.ToUpper())
|
||||||
|
{
|
||||||
|
case "GET":
|
||||||
|
sw = Stopwatch.StartNew();
|
||||||
|
|
||||||
|
while (sw.ElapsedMilliseconds < lTime)
|
||||||
|
{
|
||||||
|
Console.WriteLine("GET " + url + $" [{sw.ElapsedMilliseconds / 1000.0} s]");
|
||||||
|
client.GetAsync(url);
|
||||||
|
}
|
||||||
|
sw.Stop();
|
||||||
|
break;
|
||||||
|
case "POST":
|
||||||
|
if (!string.IsNullOrEmpty(body))
|
||||||
|
{
|
||||||
|
sw = Stopwatch.StartNew();
|
||||||
|
while (sw.ElapsedMilliseconds < lTime)
|
||||||
|
{
|
||||||
|
Console.WriteLine("POST" + url + $" [{sw.ElapsedMilliseconds / 1000.0} s]");
|
||||||
|
client.PostAsync(url, new StringContent(body));
|
||||||
|
}
|
||||||
|
sw.Stop();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user