RemotePlayerTestController.cs
4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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 UnityEditor.TestTools.TestRunner.DelayedCallback 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 RemoteTestResultReceiver 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, PlayerAliveHeartbeat);
}
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 PlayerAliveHeartbeat(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 UnityEditor.TestTools.TestRunner.DelayedCallback(TimeoutCallback, m_HearbeatTimeOut);
}
public void PostSuccessfulLaunchAction()
{
m_PlatformSpecificSetup.PostSuccessfulLaunchAction();
}
}
}