-
-
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.
feat: display user-friendly log with an unexpected messages. (#417)
display user-friendly log with an unexpected messages. ### Before: > Unknown message ID 1234 connection(...). May be due to no existing RegisterHandler for this message. ### After: > "Unexpected message Mirror.SceneMessage received in connection(...). Did you register a handler for it?"
- Loading branch information
Showing
6 changed files
with
181 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.IO; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
using UnityEngine; | ||
|
||
namespace Mirror.Tests | ||
{ | ||
public class NetworkConnectionTest : MonoBehaviour | ||
{ | ||
[Test] | ||
public void NoHandler() | ||
{ | ||
var connection = new NetworkConnection(Substitute.For<IConnection>()); | ||
|
||
int messageId = MessagePacker.GetId<SceneMessage>(); | ||
var reader = new NetworkReader(new byte[] { 1, 2, 3, 4 }); | ||
InvalidDataException exception = Assert.Throws<InvalidDataException>(() => | ||
{ | ||
connection.InvokeHandler(messageId, reader, 0); | ||
}); | ||
|
||
Assert.That(exception.Message, Does.StartWith("Unexpected message Mirror.SceneMessage received")); | ||
} | ||
|
||
[Test] | ||
public void UnknownMessage() | ||
{ | ||
var connection = new NetworkConnection(Substitute.For<IConnection>()); | ||
|
||
int messageId = MessagePacker.GetId<SceneMessage>(); | ||
var reader = new NetworkReader(new byte[] { 1, 2, 3, 4 }); | ||
InvalidDataException exception = Assert.Throws<InvalidDataException>(() => | ||
{ | ||
// some random id with no message | ||
connection.InvokeHandler(1234, reader, 0); | ||
}); | ||
|
||
Assert.That(exception.Message, Does.StartWith("Unexpected message ID 1234 received")); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.