I want to simulate a login stress test to LDAP.
send a auth request to LDAP from multiple request at the same time.
I wrote the following:
static void Main(string[] args)
{
string a = "", b = "", c = "", d = "",
e = "", f = "", g = "", h = "", i = "", j = "", k = "";
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
var startTime = DateTime.Now.ToString("hh:mm:ss.fff tt");
Parallel.Invoke
(
() => a = LdsConnection.Auth("username", "password", true),
() => b = LdsConnection.Auth("username", "password", true),
() => c = LdsConnection.Auth("username", "password", true),
() => d = LdsConnection.Auth("username", "password", true),
() => e = LdsConnection.Auth("username", "password", true),
() => f = LdsConnection.Auth("username", "password", true),
() => g = LdsConnection.Auth("username", "password", true),
() => h = LdsConnection.Auth("username", "password", true),
() => i = LdsConnection.Auth("username", "password", true),
() => j = LdsConnection.Auth("username", "password", true),
() => k = LdsConnection.Auth("username", "password", true)
);
stopwatch.Stop();
var endTime = DateTime.Now.ToString("hh:mm:ss.fff tt");
Console.WriteLine(a + "\n");
Console.WriteLine(b + "\n");
Console.WriteLine(c + "\n");
Console.WriteLine(d + "\n");
Console.WriteLine(e + "\n");
Console.WriteLine(f + "\n");
Console.WriteLine(g + "\n");
Console.WriteLine(h + "\n");
Console.WriteLine(j + "\n");
Console.WriteLine(k + "\n");
// Total run time
Console.WriteLine("Started:{0}\nEnded: {1}\nElapsed: {2}",
startTime, endTime, stopwatch.Elapsed);
Console.ReadKey();
}
public static string Auth (string username, string password, bool fullDn)
{
var url = GenerateUrl(fullDn);
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
var startTime = DateTime.Now.ToString("hh:mm:ss.fff tt");
try
{
Connect(username, password, url);
stopwatch.Stop();
var elaps = stopwatch.Elapsed.ToString();
var endTime = DateTime.Now.ToString("hh:mm:ss.fff tt");
return string.Format("Started:{0}\nEnded: {1}\nElapsed: {2}",
startTime, endTime, elaps);
}
catch (Exception exception)
{
return "Error";
}
}
The problems are:
- How can i automate this, for example a parameter which represent the number of calls in place of calling the same function multiple time manually becuase the username and the password is the same for all functions?
- I'm not really sure if all calls are requesting authentication at the same time.
Any tips please?