mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
fix: Fallback and Multiplex now disable their transports when they are disabled (#2048)
* test to check if fallbacks disables other transport * using ondisable to disable other transport * fixing teardown * adding test for Multiplex * using ondisable to disable other transport * fixing NSubstitute for 2019
This commit is contained in:
parent
ab1b92f74b
commit
61d44b2d80
@ -27,6 +27,16 @@ public void Awake()
|
||||
Debug.Log("FallbackTransport available: " + available.GetType());
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
available.enabled = true;
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
available.enabled = false;
|
||||
}
|
||||
|
||||
// The client just uses the first transport available
|
||||
Transport GetAvailableTransport()
|
||||
{
|
||||
|
@ -26,6 +26,22 @@ public void Awake()
|
||||
InitServer();
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
foreach (Transport transport in transports)
|
||||
{
|
||||
transport.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
foreach (Transport transport in transports)
|
||||
{
|
||||
transport.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Available()
|
||||
{
|
||||
// available if any of the transports is available
|
||||
|
105
Assets/Mirror/Tests/Runtime/FallbackTransportEnableTest.cs
Normal file
105
Assets/Mirror/Tests/Runtime/FallbackTransportEnableTest.cs
Normal file
@ -0,0 +1,105 @@
|
||||
using NSubstitute;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror.Tests.Runtime.TransportEnableTest
|
||||
{
|
||||
public class FallbackTransportEnableTest
|
||||
{
|
||||
Transport transport1;
|
||||
MemoryTransport transport2;
|
||||
FallbackTransport transport;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
GameObject gameObject = new GameObject();
|
||||
// set inactive so that awake isnt called
|
||||
gameObject.SetActive(false);
|
||||
|
||||
transport1 = Substitute.For<Transport>();
|
||||
transport2 = gameObject.AddComponent<MemoryTransport>();
|
||||
|
||||
transport = gameObject.AddComponent<FallbackTransport>();
|
||||
transport.transports = new[] { transport1, transport2 };
|
||||
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(transport.gameObject);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DisableShouldDisableAvailableTransport()
|
||||
{
|
||||
// make transport2 the active transport
|
||||
transport1.Available().Returns(false);
|
||||
transport.Awake();
|
||||
|
||||
// starts enabled
|
||||
Assert.That(transport2.enabled, Is.True);
|
||||
|
||||
// disabling FallbackTransport
|
||||
transport.enabled = false;
|
||||
Assert.That(transport2.enabled, Is.False);
|
||||
|
||||
// enabling FallbackTransport
|
||||
transport.enabled = true;
|
||||
Assert.That(transport2.enabled, Is.True);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class MultiplexTransportEnableTest
|
||||
{
|
||||
MemoryTransport transport1;
|
||||
MemoryTransport transport2;
|
||||
MultiplexTransport transport;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
GameObject gameObject = new GameObject();
|
||||
// set inactive so that awake isnt called
|
||||
gameObject.SetActive(false);
|
||||
|
||||
transport1 = gameObject.AddComponent<MemoryTransport>();
|
||||
transport2 = gameObject.AddComponent<MemoryTransport>();
|
||||
|
||||
transport = gameObject.AddComponent<MultiplexTransport>();
|
||||
transport.transports = new[] { transport1, transport2 };
|
||||
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(transport.gameObject);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DisableShouldDisableAllTransports()
|
||||
{
|
||||
transport.Awake();
|
||||
|
||||
// starts enabled
|
||||
Assert.That(transport1.enabled, Is.True);
|
||||
Assert.That(transport2.enabled, Is.True);
|
||||
|
||||
// disabling MultiplexTransport
|
||||
transport.enabled = false;
|
||||
Assert.That(transport1.enabled, Is.False);
|
||||
Assert.That(transport2.enabled, Is.False);
|
||||
|
||||
// enabling MultiplexTransport
|
||||
transport.enabled = true;
|
||||
Assert.That(transport1.enabled, Is.True);
|
||||
Assert.That(transport2.enabled, Is.True);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fcb8a073738084f45822dc5e559a792d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -11,8 +11,12 @@
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"overrideReferences": true,
|
||||
"precompiledReferences": [
|
||||
"NSubstitute.dll",
|
||||
"Castle.Core.dll",
|
||||
"System.Threading.Tasks.Extensions.dll"
|
||||
],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": []
|
||||
}
|
Loading…
Reference in New Issue
Block a user