Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6d185e5
moving orchestration to this branch from test/multiprocess-testing/wip
SamuelBellomo Jun 27, 2021
23e435a
cleanup
SamuelBellomo Jun 27, 2021
c38a957
better name
SamuelBellomo Jun 27, 2021
b1656ae
consistent naming
SamuelBellomo Jul 5, 2021
4ddcd25
Apply suggestions from code review
SamuelBellomo Jul 5, 2021
55e6853
Applying suggestions
SamuelBellomo Jul 5, 2021
310a78d
Merge branch 'test/multiprocess-tests/orchestration' of github.com:Un…
SamuelBellomo Jul 5, 2021
7221712
should be kept public for following PR
SamuelBellomo Jul 5, 2021
a3b98a0
Merge branch 'develop' into test/multiprocess-tests/orchestration
0xFA11 Jul 6, 2021
0b37b63
Merge branch 'test/multiprocess-tests/orchestration' of github.com:Un…
SamuelBellomo Jul 6, 2021
f6309e9
fix/cleanup asmdefs again
0xFA11 Jul 6, 2021
cd809ec
Apply suggestions from code review
SamuelBellomo Jul 6, 2021
6f7469b
Merge branch 'develop' into test/multiprocess-tests/orchestration
0xFA11 Jul 8, 2021
29e05bb
no longer ignore '[Ss]treamingAssets/buildInfo.txt'
0xFA11 Jul 8, 2021
ed2519c
PR suggestions
SamuelBellomo Jul 8, 2021
b08561a
changing root menu
SamuelBellomo Jul 8, 2021
1c9fb6c
#
SamuelBellomo Jul 8, 2021
c6d3b4a
rename test scene
SamuelBellomo Jul 8, 2021
2aa372b
Update testproject/Assets/Tests/Runtime/MultiprocessRuntime/Helpers/B…
SamuelBellomo Jul 8, 2021
3b6bfd8
Merge branch 'test/multiprocess-tests/orchestration' of github.com:Un…
SamuelBellomo Jul 8, 2021
90fffe4
#
SamuelBellomo Jul 8, 2021
2c915e9
simpler flow
SamuelBellomo Jul 8, 2021
9a3bd9b
fixes
SamuelBellomo Jul 8, 2021
49d90b4
minor touch
0xFA11 Jul 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"optionalUnityReferences": [
"TestAssemblies"
],
"includePlatforms": [],
"excludePlatforms": []
"defineConstraints": [
"UNITY_INCLUDE_TESTS",
"UNITY_EDITOR"
]
}
8 changes: 8 additions & 0 deletions testproject/Assets/Scenes.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions testproject/Assets/StreamingAssets.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
7 changes: 7 additions & 0 deletions testproject/Assets/StreamingAssets/empty.txt.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions testproject/Assets/Tests/Runtime/MultiprocessRuntime.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using System;
using System.IO;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.Build.Reporting;
#endif
using UnityEngine;

/// <summary>
/// This is needed as Unity throws "An abnormal situation has occurred: the PlayerLoop internal function has been called recursively. Please contact Customer Support with a sample project so that we can reproduce the problem and troubleshoot it."
/// when trying to build from Setup() steps in tests.
Comment thread
0xFA11 marked this conversation as resolved.
/// </summary>
public static class BuildMultiprocessTestPlayer
{
public const string MultiprocessBaseMenuName = "MLAPI/Multiprocess Test";
public const string BuildAndExecuteMenuName = MultiprocessBaseMenuName + "/Build Test Player #t";
public const string MainSceneName = "MultiprocessTestScene";
private static string BuildPathDirectory => Path.Combine(Path.GetDirectoryName(Application.dataPath), "Builds","MultiprocessTests");
public static string BuildPath => Path.Combine(BuildPathDirectory, "MultiprocessTestPlayer");

#if UNITY_EDITOR
[MenuItem(BuildAndExecuteMenuName)]
public static void BuildRelease()
{
var report = BuildPlayer();
if (report.summary.result != BuildResult.Succeeded)
{
throw new Exception($"Build failed! {report.summary.totalErrors} errors");
}
}

[MenuItem(MultiprocessBaseMenuName + "/Build Test Player (Debug)")]
public static void BuildDebug()
{
var report = BuildPlayer(true);
if (report.summary.result != BuildResult.Succeeded)
{
throw new Exception($"Build failed! {report.summary.totalErrors} errors");
}
}

[MenuItem(MultiprocessBaseMenuName + "/Delete Test Build")]
public static void DeleteBuild()
{
if (Directory.Exists(BuildPathDirectory))
{
Directory.Delete(BuildPathDirectory, recursive: true);
}
else
{
Debug.Log($"[{nameof(BuildMultiprocessTestPlayer)}] build directory does not exist ({BuildPathDirectory}) not deleting anything");
}
}

/// <summary>
/// Needs a separate build than the standalone test builds since we don't want the player to try to connect to the editor to do test
/// reporting. We only want to main node to do that, worker nodes should be dumb
/// </summary>
/// <returns></returns>
private static BuildReport BuildPlayer(bool isDebug = false)
{
// Save standalone build path to file so we can read it from standalone tests (that are not running from editor)
File.WriteAllText(Path.Combine(Application.streamingAssetsPath, MultiprocessOrchestration.BuildInfoFileName), BuildPath);

// deleting so we don't end up testing on outdated builds if there's a build failure
DeleteBuild();

var buildOptions = BuildOptions.None;
buildOptions |= BuildOptions.IncludeTestAssemblies;
buildOptions |= BuildOptions.StrictMode;
if (isDebug)
Comment thread
SamuelBellomo marked this conversation as resolved.
{
buildOptions |= BuildOptions.Development;
buildOptions |= BuildOptions.AllowDebugging; // enable this if you want to debug your players. Your players
// will have more connection permission popups when launching though
}

var buildPathToUse = BuildPath;
if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor)
{
buildPathToUse += ".exe";
}
Debug.Log($"Starting multiprocess player build using path {buildPathToUse}");

buildOptions &= ~BuildOptions.AutoRunPlayer;
var buildReport = BuildPipeline.BuildPlayer(
new[] { $"Assets/Scenes/{MainSceneName}.unity" },
buildPathToUse,
EditorUserBuildSettings.activeBuildTarget,
buildOptions);

Debug.Log("Build finished");
return buildReport;
}
#endif
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using UnityEngine;
using Debug = UnityEngine.Debug;

public class MultiprocessOrchestration
{
public const string BuildInfoFileName = "buildInfo.txt";
public const string IsWorkerArg = "-isWorker";

public static void StartWorkerNode()
{
var workerProcess = new Process();

//TODO this should be replaced eventually by proper orchestration for all supported platforms
Comment thread
SamuelBellomo marked this conversation as resolved.
// Starting new local processes is a solution to help run perf tests locally. CI should have multi machine orchestration to
// run performance tests with more realistic conditions.
string buildInstructions = $"You probably didn't generate your build. Please make sure you build a player using the '{BuildMultiprocessTestPlayer.BuildAndExecuteMenuName}' menu";
try
{
var buildInfo = File.ReadAllText(Path.Combine(Application.streamingAssetsPath, BuildInfoFileName));
switch (Application.platform)
{
case RuntimePlatform.OSXPlayer:
case RuntimePlatform.OSXEditor:
workerProcess.StartInfo.FileName = $"{buildInfo}.app/Contents/MacOS/testproject";
break;
case RuntimePlatform.WindowsPlayer:
case RuntimePlatform.WindowsEditor:
workerProcess.StartInfo.FileName = $"{buildInfo}.exe";
break;
default:
throw new NotImplementedException($"{nameof(StartWorkerNode)}: Current platform is not supported");
}
}
catch (FileNotFoundException)
{
Debug.LogError($"Could not find build info file. {buildInstructions}");
throw;
}

workerProcess.StartInfo.UseShellExecute = false;
workerProcess.StartInfo.RedirectStandardError = true;
workerProcess.StartInfo.RedirectStandardOutput = true;
workerProcess.StartInfo.Arguments = $"{IsWorkerArg} -popupwindow -screen-width 100 -screen-height 100";
// workerNode.StartInfo.Arguments += " -deepprofiling"; // enable for deep profiling
try
{
var newProcessStarted = workerProcess.Start();
if (!newProcessStarted)
{
throw new Exception("Failed to start worker process!");
}
}
catch (Win32Exception e)
{
Debug.LogError($"Error starting player, {buildInstructions}, {e.Message} {e.Data} {e.ErrorCode}");
throw;
}
Comment thread
SamuelBellomo marked this conversation as resolved.
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
{
"name": "TestProject.RuntimeTests",
"references": [
"TestProject.ManualTests",
"Unity.Multiplayer.MLAPI.Runtime",
"Unity.Multiplayer.MLAPI.RuntimeTests",
"TestProject.ManualTests"
"Unity.Multiplayer.MLAPI.RuntimeTests"
],
"optionalUnityReferences": [
"TestAssemblies"
],
"defineConstraints": [
"UNITY_INCLUDE_TESTS",
"UNITY_EDITOR"
]
}