2019-06-24 12:01:34 -04:00
|
|
|
|
using IW4MAdmin.Application;
|
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using System;
|
2018-08-28 17:32:59 -04:00
|
|
|
|
using System.Collections.Generic;
|
2019-06-24 12:01:34 -04:00
|
|
|
|
using System.IO;
|
2018-08-28 17:32:59 -04:00
|
|
|
|
using System.Text;
|
2019-06-24 12:01:34 -04:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using Xunit;
|
2018-08-28 17:32:59 -04:00
|
|
|
|
|
|
|
|
|
namespace Tests
|
|
|
|
|
{
|
2019-06-24 12:01:34 -04:00
|
|
|
|
[Collection("ManagerCollection")]
|
|
|
|
|
public class ServerTests
|
2018-08-28 17:32:59 -04:00
|
|
|
|
{
|
2019-06-24 12:01:34 -04:00
|
|
|
|
private readonly ApplicationManager _manager;
|
|
|
|
|
|
|
|
|
|
public ServerTests(ManagerFixture fixture)
|
|
|
|
|
{
|
|
|
|
|
_manager = fixture.Manager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void AddAndRemoveClientViaLog()
|
|
|
|
|
{
|
|
|
|
|
var resetEvent = new ManualResetEventSlim();
|
|
|
|
|
var server = _manager.Servers[0];
|
|
|
|
|
|
|
|
|
|
var currentClientCount = server.ClientNum;
|
|
|
|
|
int eventsProcessed = 0;
|
|
|
|
|
|
2019-11-15 15:50:20 -05:00
|
|
|
|
/*_manager.OnServerEvent += (sender, eventArgs) =>
|
2019-06-24 12:01:34 -04:00
|
|
|
|
{
|
|
|
|
|
if (eventArgs.Event.Type == GameEvent.EventType.Connect)
|
|
|
|
|
{
|
2019-11-15 15:50:20 -05:00
|
|
|
|
eventArgs.Event.Complete();
|
2019-06-24 12:01:34 -04:00
|
|
|
|
Assert.False(eventArgs.Event.Failed, "connect event was not processed");
|
|
|
|
|
Assert.True(server.ClientNum == currentClientCount + 1, "client count was not incremented");
|
|
|
|
|
eventsProcessed++;
|
|
|
|
|
resetEvent.Set();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (eventArgs.Event.Type == GameEvent.EventType.Disconnect)
|
|
|
|
|
{
|
2019-11-15 15:50:20 -05:00
|
|
|
|
eventArgs.Event.Complete();
|
2019-06-24 12:01:34 -04:00
|
|
|
|
Assert.False(eventArgs.Event.Failed, "disconnect event was not processed");
|
|
|
|
|
Assert.True(server.ClientNum == currentClientCount, "client count was not decremented");
|
|
|
|
|
eventsProcessed++;
|
|
|
|
|
resetEvent.Set();
|
|
|
|
|
}
|
2019-11-15 15:50:20 -05:00
|
|
|
|
};*/
|
2019-06-24 12:01:34 -04:00
|
|
|
|
|
|
|
|
|
server.EmulateClientJoinLog();
|
|
|
|
|
|
|
|
|
|
resetEvent.Wait(15000);
|
|
|
|
|
resetEvent.Reset();
|
|
|
|
|
|
|
|
|
|
Assert.Equal(1, eventsProcessed);
|
|
|
|
|
|
|
|
|
|
server.EmulateClientQuitLog();
|
|
|
|
|
|
|
|
|
|
resetEvent.Wait(15000);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(2, eventsProcessed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void AddAndRemoveClientViaRcon()
|
|
|
|
|
{
|
|
|
|
|
var resetEvent = new ManualResetEventSlim();
|
|
|
|
|
var server = _manager.Servers[0];
|
|
|
|
|
|
|
|
|
|
var currentClientCount = server.ClientNum;
|
|
|
|
|
int eventsProcessed = 0;
|
|
|
|
|
|
|
|
|
|
_manager.GetApplicationSettings().Configuration().RConPollRate = 5000;
|
2019-11-15 15:50:20 -05:00
|
|
|
|
/*_manager.OnServerEvent += (sender, eventArgs) =>
|
2019-06-24 12:01:34 -04:00
|
|
|
|
{
|
|
|
|
|
if (eventArgs.Event.Type == GameEvent.EventType.Connect)
|
|
|
|
|
{
|
2019-11-15 15:50:20 -05:00
|
|
|
|
eventArgs.Event.Complete();
|
2019-06-24 12:01:34 -04:00
|
|
|
|
Assert.False(eventArgs.Event.Failed, "connect event was not processed");
|
|
|
|
|
Assert.True(server.ClientNum == currentClientCount + 1, "client count was not incremented");
|
|
|
|
|
eventsProcessed++;
|
|
|
|
|
resetEvent.Set();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (eventArgs.Event.Type == GameEvent.EventType.Disconnect)
|
|
|
|
|
{
|
2019-11-15 15:50:20 -05:00
|
|
|
|
eventArgs.Event.Complete();
|
2019-06-24 12:01:34 -04:00
|
|
|
|
Assert.False(eventArgs.Event.Failed, "disconnect event was not processed");
|
|
|
|
|
Assert.True(server.ClientNum == currentClientCount, "client count was not decremented");
|
|
|
|
|
eventsProcessed++;
|
|
|
|
|
resetEvent.Set();
|
|
|
|
|
}
|
2019-11-15 15:50:20 -05:00
|
|
|
|
};*/
|
2019-06-24 12:01:34 -04:00
|
|
|
|
|
|
|
|
|
(server.RconParser as TestRconParser).FakeClientCount = 1;
|
|
|
|
|
|
|
|
|
|
resetEvent.Wait(15000);
|
|
|
|
|
resetEvent.Reset();
|
|
|
|
|
|
|
|
|
|
Assert.Equal(1, eventsProcessed);
|
|
|
|
|
|
|
|
|
|
(server.RconParser as TestRconParser).FakeClientCount = 0;
|
|
|
|
|
|
|
|
|
|
resetEvent.Wait(15000);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(2, eventsProcessed);
|
|
|
|
|
|
|
|
|
|
_manager.GetApplicationSettings().Configuration().RConPollRate = int.MaxValue;
|
|
|
|
|
}
|
2018-08-28 17:32:59 -04:00
|
|
|
|
}
|
|
|
|
|
}
|