Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
62 changes: 31 additions & 31 deletions Assets/Editor/EditorDelayManualTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
namespace io.github.hatayama.UnityCliLoop.Dev
{
/// <summary>
/// Manual testing class for EditorDelay
/// Manual testing class for EditorFrameWaiter.
/// Real-time test execution from Unity Editor menu
/// </summary>
public static class EditorDelayManualTests
public static class EditorFrameWaiterManualTests
{
private static int testFrameStart;
private static int testCounter = 0;

[MenuItem("UnityCliLoop/Debug/EditorDelay Tests/Basic Delay Tests")]
[MenuItem("UnityCliLoop/Debug/EditorFrameWaiter Tests/Basic Frame Wait Tests")]
public static void TestBasicDelays()
{
Debug.Log("========================================");
Debug.Log("=== EditorDelay Basic Tests Started ===");
Debug.Log("=== EditorFrameWaiter Basic Tests Started ===");
Debug.Log("========================================");

testFrameStart = Time.frameCount;
Expand All @@ -37,7 +37,7 @@ private static async Task TestZeroFrameDelayAsync()
int currentFrame = Time.frameCount;
Debug.Log($"[Test {++testCounter}] Zero Frame Delay - Start (Frame: {currentFrame})");

await EditorDelay.DelayFrame(0);
await EditorFrameWaiter.WaitFramesAsync(0);

int completionFrame = Time.frameCount;
Debug.Log($"[Test {testCounter}] Zero Frame Delay - Complete (Frame: {completionFrame}) - Immediate: {currentFrame == completionFrame}");
Expand All @@ -48,7 +48,7 @@ private static async Task TestSingleFrameDelayAsync()
int currentFrame = Time.frameCount;
Debug.Log($"[Test {++testCounter}] Single Frame Delay - Start (Frame: {currentFrame})");

await EditorDelay.DelayFrame(1);
await EditorFrameWaiter.WaitFramesAsync(1);

int completionFrame = Time.frameCount;
int framesDiff = completionFrame - currentFrame;
Expand All @@ -61,14 +61,14 @@ private static async Task TestMultipleFrameDelayAsync()
int currentFrame = Time.frameCount;
Debug.Log($"[Test {++testCounter}] Multiple Frame Delay ({delayFrames}) - Start (Frame: {currentFrame})");

await EditorDelay.DelayFrame(delayFrames);
await EditorFrameWaiter.WaitFramesAsync(delayFrames);

int completionFrame = Time.frameCount;
int framesDiff = completionFrame - currentFrame;
Debug.Log($"[Test {testCounter}] Multiple Frame Delay - Complete (Frame: {completionFrame}) - Frames elapsed: {framesDiff}");
}

[MenuItem("UnityCliLoop/Debug/EditorDelay Tests/Concurrent Execution Test")]
[MenuItem("UnityCliLoop/Debug/EditorFrameWaiter Tests/Concurrent Execution Test")]
public static void TestConcurrentExecution()
{
Debug.Log("=========================================");
Expand All @@ -92,14 +92,14 @@ private static async Task ConcurrentTaskAsync(string taskName, int frames)
int startFrame = Time.frameCount;
Debug.Log($"Task {taskName}: Start (Frame: {startFrame}, Delay: {frames} frames)");

await EditorDelay.DelayFrame(frames);
await EditorFrameWaiter.WaitFramesAsync(frames);

int endFrame = Time.frameCount;
int elapsed = endFrame - testFrameStart;
Debug.Log($"Task {taskName}: Complete (Frame: {endFrame}, Total elapsed: {elapsed} frames)");
}

[MenuItem("UnityCliLoop/Debug/EditorDelay Tests/Stress Test (100 Tasks)")]
[MenuItem("UnityCliLoop/Debug/EditorFrameWaiter Tests/Stress Test (100 Tasks)")]
public static void TestStressLoad()
{
Debug.Log("==============================");
Expand All @@ -110,7 +110,7 @@ public static void TestStressLoad()
int completedCount = 0;

Debug.Log($"Starting {taskCount} concurrent tasks...");
Debug.Log($"Initial Pending Tasks: {EditorDelayManager.PendingTaskCount}");
Debug.Log($"Initial Pending Waits: {EditorFrameWaiter.PendingWaitCount}");

for (int i = 0; i < taskCount; i++)
{
Expand All @@ -122,21 +122,21 @@ public static void TestStressLoad()
{
Debug.Log($"=== Stress Test Complete ===");
Debug.Log($"Completed Tasks: {completedCount}/{taskCount}");
Debug.Log($"Remaining Pending Tasks: {EditorDelayManager.PendingTaskCount}");
Debug.Log($"Remaining Pending Waits: {EditorFrameWaiter.PendingWaitCount}");
}
}).Forget();
}

Debug.Log($"All tasks started. Pending Tasks: {EditorDelayManager.PendingTaskCount}");
Debug.Log($"All tasks started. Pending Waits: {EditorFrameWaiter.PendingWaitCount}");
}

private static async Task StressTaskAsync(int taskId, Action onComplete)
{
await EditorDelay.DelayFrame(2); // All tasks execute after 2 frames
await EditorFrameWaiter.WaitFramesAsync(2); // All tasks execute after 2 frames
onComplete?.Invoke();
}

[MenuItem("UnityCliLoop/Debug/EditorDelay Tests/Cancellation Test")]
[MenuItem("UnityCliLoop/Debug/EditorFrameWaiter Tests/Cancellation Test")]
public static void TestCancellation()
{
Debug.Log("==============================");
Expand All @@ -160,7 +160,7 @@ private static async Task TestCancellableTaskAsync(CancellationToken cancellatio
try
{
Debug.Log("Cancellable Task: Start (will be cancelled)");
await EditorDelay.DelayFrame(10, cancellationToken);
await EditorFrameWaiter.WaitFramesAsync(10, cancellationToken);
Debug.Log("Cancellable Task: Complete (should not reach here)");
}
catch (OperationCanceledException)
Expand All @@ -173,14 +173,14 @@ private static async Task TestCancellableTaskAsync(CancellationToken cancellatio
}
}

[MenuItem("UnityCliLoop/Debug/EditorDelay Tests/Integration Test")]
[MenuItem("UnityCliLoop/Debug/EditorFrameWaiter Tests/Integration Test")]
public static void TestUnityCliLoopServerControllerIntegration()
{
Debug.Log("==========================================");
Debug.Log("=== UnityCliLoopServerController Integration Test ===");
Debug.Log("==========================================");

Debug.Log("Testing EditorDelay integration with UnityCliLoopServerController...");
Debug.Log("Testing EditorFrameWaiter integration with UnityCliLoopServerController...");
Debug.Log("This will simulate the actual usage in server restoration.");

SimulateServerRestorationAsync().Forget();
Expand All @@ -191,42 +191,42 @@ private static async Task SimulateServerRestorationAsync()
Debug.Log("Simulation: Starting server restoration sequence...");

// Test with the same pattern as UnityCliLoopServerController
await EditorDelay.DelayFrame(1);
await EditorFrameWaiter.WaitFramesAsync(1);
Debug.Log("Simulation: Phase 1 - Port release wait completed");

await EditorDelay.DelayFrame(1);
await EditorFrameWaiter.WaitFramesAsync(1);
Debug.Log("Simulation: Phase 2 - Server startup completed");

await EditorDelay.DelayFrame(1);
await EditorFrameWaiter.WaitFramesAsync(1);
Debug.Log("Simulation: Phase 3 - Notification sent");

Debug.Log("Simulation: Server restoration sequence completed!");
}

[MenuItem("UnityCliLoop/Debug/EditorDelay Tests/Show Manager Status")]
[MenuItem("UnityCliLoop/Debug/EditorFrameWaiter Tests/Show Waiter Status")]
public static void ShowDelayManagerStatus()
{
Debug.Log("==============================");
Debug.Log("=== EditorDelayManager Status ===");
Debug.Log("=== EditorFrameWaiter Status ===");
Debug.Log("==============================");
Debug.Log($"Pending Tasks: {EditorDelayManager.PendingTaskCount}");
Debug.Log($"Pending Waits: {EditorFrameWaiter.PendingWaitCount}");
Debug.Log($"Current Frame: {Time.frameCount}");
Debug.Log($"Time Since Startup: {EditorApplication.timeSinceStartup:F2}s");
}

[MenuItem("UnityCliLoop/Debug/EditorDelay Tests/Clear All Tasks")]
[MenuItem("UnityCliLoop/Debug/EditorFrameWaiter Tests/Clear All Waits")]
public static void ClearAllTasks()
{
int clearedCount = EditorDelayManager.PendingTaskCount;
EditorDelayManager.ClearAllTasks();
Debug.Log($"Cleared {clearedCount} pending tasks from EditorDelayManager");
int clearedCount = EditorFrameWaiter.PendingWaitCount;
EditorFrameWaiter.ClearAllForTests();
Debug.Log($"Cleared {clearedCount} pending waits from EditorFrameWaiter");
}

[MenuItem("UnityCliLoop/Debug/EditorDelay Tests/Show Test Instructions")]
[MenuItem("UnityCliLoop/Debug/EditorFrameWaiter Tests/Show Test Instructions")]
public static void ShowTestInstructions()
{
Debug.Log("=======================================");
Debug.Log("=== EditorDelay Test Instructions ===");
Debug.Log("=== EditorFrameWaiter Test Instructions ===");
Debug.Log("=======================================");
Debug.Log("1. Basic Delay Tests - Test zero, single, and multiple frame delays");
Debug.Log("2. Concurrent Execution Test - Test parallel task execution order");
Expand All @@ -241,4 +241,4 @@ public static void ShowTestInstructions()
Debug.Log("Watch the Console for test results and frame timing!");
}
}
}
}
Loading
Loading