Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

Commit

Permalink
fixing tests fo mirror v29
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Dec 7, 2020
1 parent 68762b9 commit 5deec82
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 6 deletions.
8 changes: 8 additions & 0 deletions DebugScripts/DebugServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ public class DebugServer : MonoBehaviour

private void Start()
{

transport = GetComponent<SimpleWebTransport>();
#if MIRROR_29_0_OR_NEWER
transport.OnServerConnected = onConnect;
transport.OnServerDataReceived = onData;
transport.OnServerDisconnected = onDisconnect;
transport.OnServerError = onError;
#else
transport.OnServerConnected.AddListener(onConnect);
transport.OnServerDataReceived.AddListener(onData);
transport.OnServerDisconnected.AddListener(onDisconnect);
transport.OnServerError.AddListener(onError);
#endif
transport.ServerStart();
}

Expand Down
18 changes: 16 additions & 2 deletions tests/Runtime/Client/ClientWssTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ public IEnumerator Wss_CanConnectAndDisconnectFromServer()
public IEnumerator Wss_CanPingAndStayConnectedForTime()
{
// server gets message and sends reply
server.OnServerDataReceived.AddListener((i, data, __) =>

#if MIRROR_29_0_OR_NEWER
server.OnServerDataReceived =

#else
server.OnServerDataReceived.AddListener
#endif
((i, data, __) =>
{
Assert.That(i, Is.EqualTo(1), "Conenction Id should be 1");
Expand All @@ -58,7 +65,14 @@ public IEnumerator Wss_CanPingAndStayConnectedForTime()
byte[] relyBytes = new byte[4] { 1, 2, 3, 4 };
server.ServerSend(new List<int> { i }, 0, new ArraySegment<byte>(relyBytes));
});
client.OnClientDataReceived.AddListener((data, __) =>

#if MIRROR_29_0_OR_NEWER
server.OnClientDataReceived =

#else
server.OnClientDataReceived.AddListener
#endif
((data, __) =>
{
byte[] expectedBytes = new byte[4] { 1, 2, 3, 4 };
Expand Down
21 changes: 18 additions & 3 deletions tests/Runtime/Server/ManyClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ public class ManyClientTest : SimpleWebTestBase
public IEnumerator ManyConnect(int count)
{
int connectIndex = 1;
server.OnServerConnected.AddListener((connId) =>
#if MIRROR_29_0_OR_NEWER
server.OnServerConnected =
#else
server.OnServerConnected.AddListener
#endif
((connId) =>
{
Assert.That(connId, Is.EqualTo(connectIndex), "Clients should be connected in order with the next index");
connectIndex++;
Expand Down Expand Up @@ -58,7 +63,12 @@ public IEnumerator ManyConnect(int count)
public IEnumerator ManyPings(int count)
{
int connectIndex = 1;
server.OnServerConnected.AddListener((connId) =>
#if MIRROR_29_0_OR_NEWER
server.OnServerConnected =
#else
server.OnServerConnected.AddListener
#endif
((connId) =>
{
Assert.That(connId == connectIndex, "Clients should be connected in order with the next index");
connectIndex++;
Expand Down Expand Up @@ -143,7 +153,12 @@ private List<byte[]>[] sortMessagesForClients(int clientCount, List<(int connId,
public IEnumerator ManySend(int count)
{
int connectIndex = 1;
server.OnServerConnected.AddListener((connId) =>
#if MIRROR_29_0_OR_NEWER
server.OnServerConnected =
#else
server.OnServerConnected.AddListener
#endif
((connId) =>
{
Assert.That(connId, Is.EqualTo(connectIndex), "Clients should be connected in order with the next index");
connectIndex++;
Expand Down
7 changes: 6 additions & 1 deletion tests/Runtime/Server/MultiBadHandshake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ public override void TearDown()
public IEnumerator MultipleGoodAndBadClients()
{
int connectIndex = 1;
server.OnServerConnected.AddListener((connId) =>
#if MIRROR_29_0_OR_NEWER
server.OnServerConnected =
#else
server.OnServerConnected.AddListener
#endif
((connId) =>
{
Assert.That(connId == connectIndex, "Clients should be connected in order with the next index");
connectIndex++;
Expand Down
14 changes: 14 additions & 0 deletions tests/Runtime/TestInstances.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,17 @@ public class ServerTestInstance : SimpleWebTransport, NeedInitTestInstance

public void Init()
{
#if MIRROR_29_0_OR_NEWER
base.OnServerConnected = (connId) => onConnect.Add(connId);
base.OnServerDisconnected = (connId) => onDisconnect.Add(connId);
base.OnServerDataReceived = (connId, data, _) => onData.Add((connId, this.CreateCopy(data)));
base.OnServerError = (connId, exception) => onError.Add((connId, exception));
#else
base.OnServerConnected.AddListener((connId) => onConnect.Add(connId));
base.OnServerDisconnected.AddListener((connId) => onDisconnect.Add(connId));
base.OnServerDataReceived.AddListener((connId, data, _) => onData.Add((connId, this.CreateCopy(data))));
base.OnServerError.AddListener((connId, exception) => onError.Add((connId, exception)));
#endif
}

public WaitUntil WaitForConnection => new WaitUntil(() => onConnect.Count >= 1);
Expand All @@ -59,10 +66,17 @@ public class ClientTestInstance : SimpleWebTransport, NeedInitTestInstance

public void Init()
{
#if MIRROR_29_0_OR_NEWER
base.OnClientConnected = () => onConnect++;
base.OnClientDisconnected = () => onDisconnect++;
base.OnClientDataReceived = (data, _) => onData.Add(this.CreateCopy(data));
base.OnClientError = (exception) => onError.Add(exception);
#else
base.OnClientConnected.AddListener(() => onConnect++);
base.OnClientDisconnected.AddListener(() => onDisconnect++);
base.OnClientDataReceived.AddListener((data, _) => onData.Add(this.CreateCopy(data)));
base.OnClientError.AddListener((exception) => onError.Add(exception));
#endif
}

public WaitUntil WaitForConnect => new WaitUntil(() => onConnect >= 1);
Expand Down

0 comments on commit 5deec82

Please sign in to comment.