-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixing order of host setup (#832)
new order: - add player to server collection - invoke client connected - invoke server connected
- Loading branch information
1 parent
772c3a9
commit 3951a40
Showing
11 changed files
with
158 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
Assets/Tests/Runtime/Host/NetworkServerMaxConnectionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Mirage.SocketLayer; | ||
using NUnit.Framework; | ||
using UnityEngine; | ||
using Object = UnityEngine.Object; | ||
|
||
namespace Mirage.Tests.Runtime.Host | ||
{ | ||
public class NetworkServerMaxConnectionTests : HostSetup<MockComponent> | ||
{ | ||
protected override Config ServerConfig => new Config | ||
{ | ||
// max is 0 becuase host connection isn't included for peer | ||
MaxConnections = 0 | ||
}; | ||
|
||
[Test] | ||
public void DisconnectsConnectionsOverMax() | ||
{ | ||
var secondGO = new GameObject(); | ||
NetworkClient secondClient = secondGO.AddComponent<NetworkClient>(); | ||
TestSocketFactory socketFactory = networkManagerGo.GetComponent<TestSocketFactory>(); | ||
|
||
secondClient.SocketFactory = socketFactory; | ||
|
||
int disconnectedCalled = 0; | ||
secondClient.Disconnected.AddListener(reason => | ||
{ | ||
disconnectedCalled++; | ||
Assert.That(reason, Is.EqualTo(ClientStoppedReason.ServerFull)); | ||
}); | ||
secondClient.Connect("localhost"); | ||
|
||
// updates both so that connect and reject message is received | ||
DoUpdate(); | ||
secondClient.Update(); | ||
|
||
Assert.That(server.Players, Has.Count.EqualTo(1)); | ||
// also check if client was disconnected (this will confirm it was rejected | ||
Assert.That(disconnectedCalled, Is.EqualTo(1)); | ||
|
||
Object.Destroy(secondGO); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Tests/Runtime/Host/NetworkServerMaxConnectionTests.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using NUnit.Framework; | ||
|
||
namespace Mirage.Tests.Runtime.Host | ||
{ | ||
public class NetworkServerNoAutoStartTest : HostSetup<MockComponent> | ||
{ | ||
protected override bool AutoStartServer => false; | ||
|
||
[Test] | ||
public void InvokeLocalConnectedThrowsIfLocalClientIsNull() | ||
{ | ||
Assert.Throws<InvalidOperationException>(() => | ||
{ | ||
server.InvokeLocalConnected(); | ||
}); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Tests/Runtime/Host/NetworkServerNoAutoStartTest.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters