Skip to content

Commit feb75d2

Browse files
committed
fix: skip UPnP/firewall in test mode to fix flaky CI
- Add SetTestMode(true) to Network service - Skips upnpDiscover(2s blocking) and firewall rule creation in tests - Tests enable test mode in SetUp() before Initialize() - This eliminates the 2-second UPnP block per HostGame call that was causing cascading timeouts in CI containers
1 parent bfc1f85 commit feb75d2

3 files changed

Lines changed: 32 additions & 17 deletions

File tree

engine/networking/network_service.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -175,25 +175,28 @@ namespace Chained
175175
m_PlayerManager.AddHostSelf(HostNetworkID, m_PlayerManager.GetLocalPlayerName(),
176176
m_PlayerManager.GetLocalSkinIndex());
177177

178-
if (!m_UpnpMapper.IsAvailable())
178+
if (!m_TestMode)
179179
{
180-
m_UpnpMapper.Initialize();
181-
}
182-
if (m_UpnpMapper.IsAvailable())
183-
{
184-
m_UpnpMapper.AddMapping(port, "UDP", "ChainedDecos");
185-
CH_CORE_INFO("Network: UPnP mapping added.");
186-
}
187-
else
188-
{
189-
CH_CORE_WARN("Network: UPnP unavailable — players must forward port {} manually.", port);
190-
}
180+
if (!m_UpnpMapper.IsAvailable())
181+
{
182+
m_UpnpMapper.Initialize();
183+
}
184+
if (m_UpnpMapper.IsAvailable())
185+
{
186+
m_UpnpMapper.AddMapping(port, "UDP", "ChainedDecos");
187+
CH_CORE_INFO("Network: UPnP mapping added.");
188+
}
189+
else
190+
{
191+
CH_CORE_WARN("Network: UPnP unavailable — players must forward port {} manually.", port);
192+
}
191193

192-
// Add Windows Firewall inbound rule
193-
m_FirewallRuleActive = Firewall::AddUDPRule(port);
194-
if (!m_FirewallRuleActive)
195-
{
196-
CH_CORE_WARN("Network: Could not add firewall rule. Run as admin to allow inbound connections.");
194+
// Add Windows Firewall inbound rule
195+
m_FirewallRuleActive = Firewall::AddUDPRule(port);
196+
if (!m_FirewallRuleActive)
197+
{
198+
CH_CORE_WARN("Network: Could not add firewall rule. Run as admin to allow inbound connections.");
199+
}
197200
}
198201

199202
{

engine/networking/network_service.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ namespace Chained
151151
return m_FirewallRuleActive;
152152
}
153153

154+
void SetTestMode(bool enabled)
155+
{
156+
m_TestMode = enabled;
157+
}
158+
bool IsTestMode() const
159+
{
160+
return m_TestMode;
161+
}
162+
154163
NetworkSession& GetSession()
155164
{
156165
return m_Session;
@@ -178,6 +187,7 @@ namespace Chained
178187
std::string m_CachedPublicIP;
179188
std::mutex m_PublicIPMutex;
180189
bool m_FirewallRuleActive = false;
190+
bool m_TestMode = false;
181191

182192
static constexpr uint64_t HostNetworkID = 1;
183193
};

tests/integration/network_tests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ namespace
2121
void SetUp() override
2222
{
2323
m_Port = kTestPortBase + (s_PortCounter.fetch_add(1) % 50);
24+
m_Host.SetTestMode(true);
25+
m_Client.SetTestMode(true);
2426
m_Host.Initialize();
2527
m_Client.Initialize();
2628
ASSERT_TRUE(m_Host.IsEnabled()) << "ENet failed to initialize";

0 commit comments

Comments
 (0)