ConnectWithDNSWorks.cs
2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System.Collections;
using NUnit.Framework;
using UnityEngine.TestTools;
using UnityEngine;
using UnityEngine.Networking;
#pragma warning disable 618
public class ConnectWithDNSWorks
{
int kListenPort = 7073;
int steps = 0;
[UnityTest]
public IEnumerator ConnectWithDNSWorksTest()
{
NetworkServer.Reset();
NetworkClient.ShutdownAll();
ConnectionConfig config = new ConnectionConfig();
config.AddChannel(QosType.ReliableSequenced);
config.AddChannel(QosType.Unreliable);
NetworkClient client1 = new NetworkClient();
if (!client1.Configure(config, 20))
{
Assert.Fail("client1 configure failed");
}
client1.RegisterHandler(MsgType.Error, OnError1);
NetworkClient client2 = new NetworkClient();
if (!client2.Configure(config, 20))
{
Assert.Fail("client2 configure failed");
}
client2.RegisterHandler(MsgType.Connect, OnConnectIncrementStep);
NetworkClient client3 = new NetworkClient();
if (!client3.Configure(config, 20))
{
Assert.Fail("client3 configure failed");
}
client3.RegisterHandler(MsgType.Connect, OnConnectIncrementStep);
int retries = 0;
while (!NetworkServer.Listen("127.0.0.1", ++kListenPort))
{
Assert.IsTrue(retries++ < 10, "Couldn't Listen for more than 10 retries");
}
// wait for errors from client1
#if PLATFORM_WINRT && !ENABLE_IL2CPP
LogAssert.Expect(LogType.Error, "DNS resolution failed: HostNotFound");
LogAssert.Expect(LogType.Error, "UNet Client Error Connect Error: 11");
#else
LogAssert.Expect(LogType.Error, "DNS resolution failed: 11001");
LogAssert.Expect(LogType.Error, "UNet Client Error Connect Error: 11");
#endif
client1.Connect("444.555.444.333", kListenPort);
// These are successful and should increment the step counter
client2.Connect("localhost", kListenPort);
client3.Connect("127.0.0.1", kListenPort);
while (steps < 3)
{
yield return null;
}
}
void OnError1(NetworkMessage netMsg)
{
UnityEngine.Networking.NetworkSystem.ErrorMessage msg = netMsg.ReadMessage<UnityEngine.Networking.NetworkSystem.ErrorMessage>();
Assert.AreEqual(NetworkError.DNSFailure, (NetworkError)msg.errorCode);
steps += 1;
}
void OnConnectIncrementStep(NetworkMessage netMsg)
{
steps += 1;
}
}
#pragma warning restore 618