Skip to content

Commit c4498e5

Browse files
committed
try connect to service utp only
1 parent 58aefa9 commit c4498e5

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

.yamato/desktop-standalone-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ desktop_standalone_test_{{ project.name }}_{{ platform.name }}_{{ backend }}_{{
8181
{% if platform.name != "win" %} # Issues with win and mac are tracked in MTT-11606
8282
variables:
8383
ECHO_SERVER_PORT: "7788"
84-
COMB_SERVER_PORT: "7799"
84+
COMB_SERVER_PORT: "7789"
8585
# Set this to ensure the DA codec tests will fail if they cannot connect to the echo-server
8686
# The default is to ignore the codec tests if the echo-server fails to connect
8787
ENSURE_CODEC_TESTS: "true"

com.unity.netcode.gameobjects/Tests/Runtime/DistributedAuthority/DistributedAuthorityConnectionTest.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
using System;
12
using System.Collections;
3+
using System.Linq;
4+
using System.Net;
25
using NUnit.Framework;
36
using Unity.Netcode.TestHelpers.Runtime;
7+
using Unity.Networking.Transport;
48
using UnityEngine;
59
using UnityEngine.TestTools;
610

@@ -67,6 +71,54 @@ public IEnumerator CreateObjectNew()
6771
AssertOnTimeout("failed to spawn object!");
6872
}
6973

74+
private static readonly string k_TransportHost = GetAddressToBind();
75+
private static readonly ushort k_TransportPort = GetPortToBind();
76+
77+
/// <summary>
78+
/// Configures the port to look for the rust service.
79+
/// </summary>
80+
/// <returns>The port from the environment variable "CMB_SERVICE_PORT" if it is set and valid; otherwise uses port 7789</returns>
81+
private static ushort GetPortToBind()
82+
{
83+
var value = Environment.GetEnvironmentVariable("CMB_SERVICE_PORT");
84+
return ushort.TryParse(value, out var configuredPort) ? configuredPort : (ushort)7789;
85+
}
86+
87+
/// <summary>
88+
/// Configures the address to look for the rust service.
89+
/// </summary>
90+
/// <returns>The address from the environment variable "NGO_HOST" if it is set and valid; otherwise uses "127.0.0.1"</returns>
91+
private static string GetAddressToBind()
92+
{
93+
var value = Environment.GetEnvironmentVariable("NGO_HOST") ?? "127.0.0.1";
94+
return Dns.GetHostAddresses(value).First().ToString();
95+
}
96+
97+
[Test]
98+
public void CanConnectToServer()
99+
{
100+
var address = Dns.GetHostAddresses(k_TransportHost).First();
101+
var endpoint = NetworkEndpoint.Parse(address.ToString(), k_TransportPort);
102+
103+
var driver = NetworkDriver.Create();
104+
var connection = driver.Connect(endpoint);
105+
106+
var start = DateTime.Now;
107+
var ev = Networking.Transport.NetworkEvent.Type.Empty;
108+
while (ev != Networking.Transport.NetworkEvent.Type.Connect)
109+
{
110+
driver.ScheduleUpdate().Complete();
111+
ev = driver.PopEventForConnection(connection, out _, out _);
112+
113+
if (DateTime.Now - start > TimeSpan.FromMilliseconds(100))
114+
{
115+
Assert.Fail("Failed to connect to comb service within time!");
116+
}
117+
}
118+
119+
driver.Disconnect(connection);
120+
}
121+
70122

71123
private bool CheckObjectExists()
72124
{

0 commit comments

Comments
 (0)