117 lines
3.5 KiB
C#
117 lines
3.5 KiB
C#
using ClientTester.DummyService;
|
|
using ClientTester.EchoDummyService;
|
|
using Serilog;
|
|
|
|
class EcoClientTester
|
|
{
|
|
public static readonly string SERVER_IP = "localhost";
|
|
public static readonly int SERVER_PORT = 9500;
|
|
public static readonly string CONNECTION_KEY = "test";
|
|
public static readonly int CLIENT_COUNT = 10;
|
|
|
|
private async Task StartEchoDummyTest()
|
|
{
|
|
try
|
|
{
|
|
CancellationTokenSource cts = new CancellationTokenSource();
|
|
Console.CancelKeyPress += (_, e) =>
|
|
{
|
|
e.Cancel = true;
|
|
Log.Warning("[SHUTDOWN] Ctrl+C 감지, 종료 중...");
|
|
cts.Cancel();
|
|
};
|
|
|
|
EchoDummyClientService service =
|
|
new EchoDummyClientService(CLIENT_COUNT, SERVER_IP, SERVER_PORT, CONNECTION_KEY, 100);
|
|
service.OnAllDisconnected += () =>
|
|
{
|
|
Log.Warning("[SHUTDOWN] 종료 이벤트 발생, 종료 중...");
|
|
cts.Cancel();
|
|
};
|
|
|
|
// service.IsTest = true;
|
|
// service.TestCount = 100;
|
|
await service.RunAsync(cts.Token);
|
|
|
|
service.PrintStats();
|
|
service.Stop();
|
|
|
|
await Log.CloseAndFlushAsync();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error($"[SHUTDOWN] 예외 발생 : {e}");
|
|
}
|
|
}
|
|
|
|
private async Task StartDummyTest()
|
|
{
|
|
try
|
|
{
|
|
CancellationTokenSource cts = new CancellationTokenSource();
|
|
Console.CancelKeyPress += (_, e) =>
|
|
{
|
|
e.Cancel = true;
|
|
Log.Warning("[SHUTDOWN] Ctrl+C 감지, 종료 중...");
|
|
cts.Cancel();
|
|
};
|
|
|
|
DummyClientService service =
|
|
new DummyClientService(CLIENT_COUNT, SERVER_IP, SERVER_PORT, CONNECTION_KEY, 100);
|
|
service.OnAllDisconnected += () =>
|
|
{
|
|
Log.Warning("[SHUTDOWN] 종료 이벤트 발생, 종료 중...");
|
|
cts.Cancel();
|
|
};
|
|
|
|
await service.RunAsync(cts.Token);
|
|
|
|
service.PrintStats();
|
|
service.Stop();
|
|
|
|
await Log.CloseAndFlushAsync();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error($"[SHUTDOWN] 예외 발생 : {e}");
|
|
}
|
|
}
|
|
|
|
private static async Task Main(string[] args)
|
|
{
|
|
// .MinimumLevel.Warning() // Warning 이상만 출력 배포시
|
|
string timestamp = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
|
|
|
|
Log.Logger = new LoggerConfiguration()
|
|
.MinimumLevel.Debug()
|
|
.WriteTo.Console()
|
|
.WriteTo.File($"logs2/log_{timestamp}.txt")
|
|
.CreateLogger();
|
|
|
|
Log.Information("========== 더미 클라 테스터 ==========");
|
|
Log.Information("1. 에코 서버");
|
|
Log.Information("2. 더미 클라(이동만)");
|
|
Log.Information("====================================");
|
|
Log.Information("1 / 2 : ");
|
|
|
|
string? input = Console.ReadLine();
|
|
if (!int.TryParse(input, out int choice) || (choice != 1 && choice != 2))
|
|
{
|
|
Log.Warning("1 또는 2만 입력하세요.");
|
|
return;
|
|
}
|
|
|
|
EcoClientTester tester = new EcoClientTester();
|
|
if (choice == 1)
|
|
{
|
|
// 에코 서버 실행
|
|
await tester.StartEchoDummyTest();
|
|
}
|
|
else if (choice == 2)
|
|
{
|
|
// 더미 클라 실행
|
|
await tester.StartDummyTest();
|
|
}
|
|
}
|
|
}
|