Skip to content

Commit aac06f9

Browse files
Address code review feedback for TestRunnerCallbacks
- Add SessionState persistence to survive domain reloads during test execution - Change DestroyImmediate to Object.Destroy for proper Unity lifecycle - Make IsRunningTests thread-safe with volatile backing field - Clear session state on editor quit Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 08636db commit aac06f9

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

UnityProject/Packages/com.jasonxudeveloper.jengine.core/Editor/Misc/TestRunnerCallbacks.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,32 @@ namespace JEngine.Core.Editor.Misc
1010
[InitializeOnLoad]
1111
internal class TestRunnerCallbacks : ICallbacks
1212
{
13+
private const string SessionStateKey = "JEngine.TestRunnerCallbacks.IsRunningTests";
14+
15+
private static volatile bool _isRunningTests;
16+
1317
/// <summary>
1418
/// Returns true when tests are currently running
1519
/// </summary>
16-
public static bool IsRunningTests { get; private set; }
20+
public static bool IsRunningTests
21+
{
22+
get => _isRunningTests;
23+
private set
24+
{
25+
_isRunningTests = value;
26+
// Persist to SessionState to survive domain reloads during test execution
27+
SessionState.SetBool(SessionStateKey, value);
28+
}
29+
}
1730

1831
private static readonly TestRunnerCallbacks _instance = new TestRunnerCallbacks();
1932
private static TestRunnerApi _api;
2033

2134
static TestRunnerCallbacks()
2235
{
36+
// Restore state after domain reload (e.g., recompilation during test run)
37+
_isRunningTests = SessionState.GetBool(SessionStateKey, false);
38+
2339
_api = ScriptableObject.CreateInstance<TestRunnerApi>();
2440
_api.RegisterCallbacks(_instance);
2541
EditorApplication.quitting += OnEditorQuitting;
@@ -32,9 +48,12 @@ private static void OnEditorQuitting()
3248
if (_api != null)
3349
{
3450
_api.UnregisterCallbacks(_instance);
35-
ScriptableObject.DestroyImmediate(_api);
51+
Object.Destroy(_api);
3652
_api = null;
3753
}
54+
55+
// Clear session state on quit
56+
SessionState.EraseBool(SessionStateKey);
3857
}
3958

4059
public void RunStarted(ITestAdaptor testsToRun)

0 commit comments

Comments
 (0)