From 5deec82e9fe902fd848d8692400e44cdb4a3f634 Mon Sep 17 00:00:00 2001 From: James Frowen Date: Mon, 7 Dec 2020 16:20:35 +0000 Subject: [PATCH] fixing tests fo mirror v29 --- DebugScripts/DebugServer.cs | 8 ++++++++ tests/Runtime/Client/ClientWssTest.cs | 18 ++++++++++++++++-- tests/Runtime/Server/ManyClientTest.cs | 21 ++++++++++++++++++--- tests/Runtime/Server/MultiBadHandshake.cs | 7 ++++++- tests/Runtime/TestInstances.cs | 14 ++++++++++++++ 5 files changed, 62 insertions(+), 6 deletions(-) diff --git a/DebugScripts/DebugServer.cs b/DebugScripts/DebugServer.cs index 9945cbb..e105d5a 100644 --- a/DebugScripts/DebugServer.cs +++ b/DebugScripts/DebugServer.cs @@ -11,11 +11,19 @@ public class DebugServer : MonoBehaviour private void Start() { + transport = GetComponent(); +#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(); } diff --git a/tests/Runtime/Client/ClientWssTest.cs b/tests/Runtime/Client/ClientWssTest.cs index 2679a45..bc93ced 100644 --- a/tests/Runtime/Client/ClientWssTest.cs +++ b/tests/Runtime/Client/ClientWssTest.cs @@ -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"); @@ -58,7 +65,14 @@ public IEnumerator Wss_CanPingAndStayConnectedForTime() byte[] relyBytes = new byte[4] { 1, 2, 3, 4 }; server.ServerSend(new List { i }, 0, new ArraySegment(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 }; diff --git a/tests/Runtime/Server/ManyClientTest.cs b/tests/Runtime/Server/ManyClientTest.cs index 3fabffc..7608cd4 100644 --- a/tests/Runtime/Server/ManyClientTest.cs +++ b/tests/Runtime/Server/ManyClientTest.cs @@ -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++; @@ -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++; @@ -143,7 +153,12 @@ private List[] 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++; diff --git a/tests/Runtime/Server/MultiBadHandshake.cs b/tests/Runtime/Server/MultiBadHandshake.cs index 2e381e1..c5c48cc 100644 --- a/tests/Runtime/Server/MultiBadHandshake.cs +++ b/tests/Runtime/Server/MultiBadHandshake.cs @@ -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++; diff --git a/tests/Runtime/TestInstances.cs b/tests/Runtime/TestInstances.cs index 6635e59..7061f11 100644 --- a/tests/Runtime/TestInstances.cs +++ b/tests/Runtime/TestInstances.cs @@ -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); @@ -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);