-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add load-testing project. Add using around webclient.
- Loading branch information
Showing
9 changed files
with
202 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Windows; | ||
|
||
namespace Remotely.Shared.Utilities | ||
{ | ||
public class CommandLineParser | ||
{ | ||
private static Dictionary<string, string> commandLineArgs; | ||
public static Dictionary<string, string> CommandLineArgs | ||
{ | ||
get | ||
{ | ||
if (commandLineArgs is null) | ||
{ | ||
commandLineArgs = new Dictionary<string, string>(); | ||
var args = Environment.GetCommandLineArgs(); | ||
for (var i = 1; i < args.Length; i += 2) | ||
{ | ||
try | ||
{ | ||
var key = args?[i]; | ||
if (key != null) | ||
{ | ||
if (!key.Contains("-")) | ||
{ | ||
i -= 1; | ||
continue; | ||
} | ||
key = key.Trim().Replace("-", "").ToLower(); | ||
if (i + 1 == args.Length) | ||
{ | ||
commandLineArgs.Add(key, "true"); | ||
continue; | ||
} | ||
var value = args[i + 1]; | ||
if (value != null) | ||
{ | ||
if (value.StartsWith("-")) | ||
{ | ||
commandLineArgs.Add(key, "true"); | ||
i -= 1; | ||
} | ||
else | ||
{ | ||
commandLineArgs.Add(key, args[i + 1].Trim()); | ||
} | ||
} | ||
} | ||
} | ||
catch { } | ||
|
||
} | ||
} | ||
return commandLineArgs; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using Microsoft.AspNetCore.SignalR.Client; | ||
using Remotely.Shared.Services; | ||
using Remotely.Shared.Utilities; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace Remotely.Tests.LoadTester | ||
{ | ||
internal class Program | ||
{ | ||
private static void Main(string[] args) | ||
{ | ||
Task.Run(ConnectAgents).Wait(); | ||
|
||
Console.Write("Press Enter to exit..."); | ||
Console.ReadLine(); | ||
} | ||
|
||
private static async Task ConnectAgents() | ||
{ | ||
try | ||
{ | ||
if (!CommandLineParser.CommandLineArgs.ContainsKey("serverurl") || | ||
!CommandLineParser.CommandLineArgs.ContainsKey("organizationid") || | ||
!CommandLineParser.CommandLineArgs.ContainsKey("agentcount")) | ||
{ | ||
Console.WriteLine("Command line arguments must include all of the following: "); | ||
Console.WriteLine(); | ||
Console.WriteLine("-serverurl [full URL of the Remotely server]"); | ||
Console.WriteLine(); | ||
Console.WriteLine("-organizationid [organization ID that the device will belong to]"); | ||
Console.WriteLine(); | ||
Console.WriteLine("-agentcount [the number of agent connections to simulate]"); | ||
Console.WriteLine(); | ||
Console.WriteLine("Press Enter to exit..."); | ||
Environment.Exit(0); | ||
} | ||
|
||
var agentCount = int.Parse(CommandLineParser.CommandLineArgs["agentcount"]); | ||
var organizationId = CommandLineParser.CommandLineArgs["organizationid"]; | ||
var serverurl = CommandLineParser.CommandLineArgs["serverurl"]; | ||
var connections = new Dictionary<string, HubConnection>(); | ||
|
||
for (var i = 0; i < agentCount; i++) | ||
{ | ||
try | ||
{ | ||
var deviceId = Guid.NewGuid().ToString(); | ||
|
||
var hubConnection = new HubConnectionBuilder() | ||
.WithUrl(serverurl + "/DeviceHub") | ||
.Build(); | ||
|
||
Console.WriteLine("Connecting device number " + i.ToString()); | ||
await hubConnection.StartAsync(); | ||
|
||
var device = await DeviceInformation.Create(deviceId, organizationId); | ||
device.DeviceName = "TestDevice-" + Guid.NewGuid(); | ||
|
||
var result = await hubConnection.InvokeAsync<bool>("DeviceCameOnline", device); | ||
|
||
if (!result) | ||
{ | ||
Console.WriteLine($"Device {i} failed to come online."); | ||
return; | ||
} | ||
|
||
var heartbeatTimer = new System.Timers.Timer(TimeSpan.FromMinutes(1).TotalMilliseconds); | ||
heartbeatTimer.Elapsed += async (sender, args) => | ||
{ | ||
var currentInfo = await DeviceInformation.Create(device.ID, organizationId); | ||
currentInfo.DeviceName = device.DeviceName; | ||
await hubConnection.SendAsync("DeviceHeartbeat", currentInfo); | ||
}; | ||
heartbeatTimer.Start(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine($"Device {i} failed to connect."); | ||
Console.WriteLine(ex.Message); | ||
} | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine("An error occurred. Check your syntex. Error: "); | ||
Console.WriteLine(); | ||
Console.WriteLine(ex.Message); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"profiles": { | ||
"Tests.LoadTester": { | ||
"commandName": "Project", | ||
"commandLineArgs": "-serverurl https://localhost:5001 -organizationid 6b8ff6b6-a5ac-4e38-a022-3b64f2e6b486 -agentcount 1000" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<AssemblyName>Remotely.Tests.LoadTester</AssemblyName> | ||
<RootNamespace>Remotely.Tests.LoadTester</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ScreenCast.Core\ScreenCast.Core.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |