diff options
| author | Andrew Lee <alee14498@protonmail.com> | 2020-04-19 17:19:32 -0400 |
|---|---|---|
| committer | Andrew Lee <alee14498@protonmail.com> | 2020-04-19 17:19:32 -0400 |
| commit | c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78 (patch) | |
| tree | ee4d51c7c1d633e11f46453ef1edd3c77c4ef9f7 /Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/TestLaunchers/RemotePlayerTestController.cs | |
| download | Project-Sandbox-c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78.tar.gz Project-Sandbox-c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78.tar.bz2 Project-Sandbox-c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78.zip | |
Inital commit
Diffstat (limited to 'Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/TestLaunchers/RemotePlayerTestController.cs')
| -rw-r--r-- | Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/TestLaunchers/RemotePlayerTestController.cs | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/TestLaunchers/RemotePlayerTestController.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/TestLaunchers/RemotePlayerTestController.cs new file mode 100644 index 0000000..87871ee --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/TestLaunchers/RemotePlayerTestController.cs @@ -0,0 +1,110 @@ +using System;
+using UnityEditor.Networking.PlayerConnection;
+using UnityEditor.TestTools.TestRunner;
+using UnityEditor.TestTools.TestRunner.Api;
+using UnityEditor.TestTools.TestRunner.UnityTestProtocol;
+using UnityEngine;
+using UnityEngine.Networking.PlayerConnection;
+using UnityEngine.TestRunner.TestLaunchers;
+
+namespace UnityEditor.TestRunner.TestLaunchers
+{
+ [Serializable]
+ internal class RemoteTestRunController : ScriptableSingleton<RemoteTestRunController>
+ {
+ internal const int k_HeartbeatTimeout = 60 * 10;
+
+ [SerializeField]
+ private RemoteTestResultReciever m_RemoteTestResultReciever;
+
+ [SerializeField]
+ private PlatformSpecificSetup m_PlatformSpecificSetup;
+
+ [SerializeField]
+ private bool m_RegisteredConnectionCallbacks;
+
+ [SerializeField]
+ private int m_HearbeatTimeOut;
+
+ private IDelayedCallback m_TimeoutCallback;
+
+ public void Init(BuildTarget buildTarget, int heartbeatTimeout)
+ {
+ m_HearbeatTimeOut = heartbeatTimeout;
+ m_PlatformSpecificSetup = new PlatformSpecificSetup(buildTarget);
+ m_PlatformSpecificSetup.Setup();
+ m_RemoteTestResultReciever = new RemoteTestResultReciever();
+ EditorConnection.instance.Initialize();
+ if (!m_RegisteredConnectionCallbacks)
+ {
+ EditorConnection.instance.Initialize();
+ DelegateEditorConnectionEvents();
+ }
+ }
+
+ private void DelegateEditorConnectionEvents()
+ {
+ m_RegisteredConnectionCallbacks = true;
+ //This is needed because RemoteTestResultReciever is not a ScriptableObject
+ EditorConnection.instance.Register(PlayerConnectionMessageIds.runStartedMessageId, RunStarted);
+ EditorConnection.instance.Register(PlayerConnectionMessageIds.runFinishedMessageId, RunFinished);
+ EditorConnection.instance.Register(PlayerConnectionMessageIds.testStartedMessageId, TestStarted);
+ EditorConnection.instance.Register(PlayerConnectionMessageIds.testFinishedMessageId, TestFinished);
+ EditorConnection.instance.Register(PlayerConnectionMessageIds.playerAliveHeartbeat, PlayerAliveHearbeat);
+ }
+
+ private void RunStarted(MessageEventArgs messageEventArgs)
+ {
+ m_TimeoutCallback?.Reset();
+ m_RemoteTestResultReciever.RunStarted(messageEventArgs);
+ CallbacksDelegator.instance.RunStartedRemotely(messageEventArgs.data);
+ }
+
+ private void RunFinished(MessageEventArgs messageEventArgs)
+ {
+ m_TimeoutCallback?.Clear();
+ m_RemoteTestResultReciever.RunFinished(messageEventArgs);
+ m_PlatformSpecificSetup.CleanUp();
+
+ CallbacksDelegator.instance.RunFinishedRemotely(messageEventArgs.data);
+ }
+
+ private void TestStarted(MessageEventArgs messageEventArgs)
+ {
+ m_TimeoutCallback?.Reset();
+ CallbacksDelegator.instance.TestStartedRemotely(messageEventArgs.data);
+ }
+
+ private void TestFinished(MessageEventArgs messageEventArgs)
+ {
+ m_TimeoutCallback?.Reset();
+ CallbacksDelegator.instance.TestFinishedRemotely(messageEventArgs.data);
+ }
+
+ private void PlayerAliveHearbeat(MessageEventArgs messageEventArgs)
+ {
+ m_TimeoutCallback?.Reset();
+ }
+
+ private void TimeoutCallback()
+ {
+ CallbacksDelegator.instance.RunFailed($"Test execution timed out. No activity received from the player in {m_HearbeatTimeOut} seconds.");
+ }
+
+ public void PostBuildAction()
+ {
+ m_PlatformSpecificSetup.PostBuildAction();
+ }
+
+ public void PostSuccessfulBuildAction()
+ {
+ m_PlatformSpecificSetup.PostSuccessfulBuildAction();
+ m_TimeoutCallback = new DelayedCallback(TimeoutCallback, m_HearbeatTimeOut);
+ }
+
+ public void PostSuccessfulLaunchAction()
+ {
+ m_PlatformSpecificSetup.PostSuccessfulLaunchAction();
+ }
+ }
+}
|
