fix: improve minigame reconnect flow

This commit is contained in:
ud18010
2026-07-29 19:30:50 +08:00
parent 6a5e534d00
commit 42c3874d82
21 changed files with 979 additions and 52 deletions
@@ -1,3 +1,4 @@
using System.IO;
using System.Reflection;
using NUnit.Framework;
using UnityEditor;
@@ -33,3 +34,84 @@ public sealed class XWorldJsonPrefabAutoConvertTests
return (bool)method.Invoke(null, null);
}
}
public sealed class XWorldLocalServerBuildTests
{
[Test]
public void LocalServerMenuUsesGatewayProjectInsteadOfPrebuiltDll()
{
string gatewayProjectPath = InvokeStringPath("GetMiniGameGatewayRunnerProjectPath");
Assert.That(gatewayProjectPath.Replace('\\', '/'), Does.EndWith("/Server/Gateway.Runner/Gateway.Runner.csproj"));
Assert.That(File.Exists(gatewayProjectPath), Is.True);
Assert.That(XWorldUtil.CanOpenLocalServer(), Is.True);
}
[Test]
public void CdnRunnerBuildMenuUsesCdnProject()
{
string cdnProjectPath = InvokeStringPath("GetMiniGameCdnRunnerProjectPath");
Assert.That(cdnProjectPath.Replace('\\', '/'), Does.EndWith("/Server/Cdn.Runner/Cdn.Runner.csproj"));
Assert.That(File.Exists(cdnProjectPath), Is.True);
}
[Test]
public void LocalServerBuildIsSkippedWhenGatewayIsAlreadyRunning()
{
Assert.That(InvokeShouldBuildLocalServer(false), Is.True);
Assert.That(InvokeShouldBuildLocalServer(true), Is.False);
}
[Test]
public void DotnetRunnerLaunchableRequiresRuntimeConfigNextToDll()
{
string tempDir = Path.Combine(Path.GetTempPath(), "XWorldRunnerTest-" + System.Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(tempDir);
try
{
string runnerPath = Path.Combine(tempDir, "Example.Runner.dll");
File.WriteAllText(runnerPath, string.Empty);
Assert.That(InvokeLaunchable(runnerPath), Is.False);
File.WriteAllText(Path.Combine(tempDir, "Example.Runner.runtimeconfig.json"), "{}");
Assert.That(InvokeLaunchable(runnerPath), Is.True);
}
finally
{
Directory.Delete(tempDir, true);
}
}
private static string InvokeStringPath(string methodName)
{
MethodInfo method = typeof(XWorldUtil).GetMethod(
methodName,
BindingFlags.Static | BindingFlags.NonPublic);
Assert.That(method, Is.Not.Null);
return (string)method.Invoke(null, null);
}
private static bool InvokeLaunchable(string runnerPath)
{
MethodInfo method = typeof(XWorldUtil).GetMethod(
"IsDotnetRunnerLaunchable",
BindingFlags.Static | BindingFlags.NonPublic);
Assert.That(method, Is.Not.Null);
return (bool)method.Invoke(null, new object[] { runnerPath });
}
private static bool InvokeShouldBuildLocalServer(bool isGatewayRunning)
{
MethodInfo method = typeof(XWorldUtil).GetMethod(
"ShouldBuildMiniGameLocalServer",
BindingFlags.Static | BindingFlags.NonPublic);
Assert.That(method, Is.Not.Null);
return (bool)method.Invoke(null, new object[] { isGatewayRunning });
}
}