Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename CancellationToken parameter/variable name #136

Merged
merged 2 commits into from
Jan 10, 2025
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
4 changes: 2 additions & 2 deletions Runtime/Agents/AbstractAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public ITerminatable AutopilotInstance
/// <summary>
/// Run agent
/// </summary>
/// <param name="token"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public abstract UniTask Run(CancellationToken token);
public abstract UniTask Run(CancellationToken cancellationToken);
}
}
6 changes: 3 additions & 3 deletions Runtime/Agents/DoNothingAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class DoNothingAgent : AbstractAgent
public long lifespanSec;

/// <inheritdoc />
public override async UniTask Run(CancellationToken token)
public override async UniTask Run(CancellationToken cancellationToken)
{
Logger.Log($"Enter {this.name}.Run()");

Expand All @@ -29,11 +29,11 @@ public override async UniTask Run(CancellationToken token)
if (lifespanSec > 0)
{
await UniTask.Delay(TimeSpan.FromSeconds(lifespanSec), ignoreTimeScale: true,
cancellationToken: token);
cancellationToken: cancellationToken);
}
else
{
await UniTask.WaitWhile(() => true, cancellationToken: token); // Wait indefinitely
await UniTask.WaitWhile(() => true, cancellationToken: cancellationToken); // Wait indefinitely
}
}
finally
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Agents/ErrorHandlerAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private static void ResetInstances()
}
}

public override async UniTask Run(CancellationToken token)
public override async UniTask Run(CancellationToken cancellationToken)
{
try
{
Expand All @@ -86,7 +86,7 @@ public override async UniTask Run(CancellationToken token)

Application.logMessageReceivedThreaded += this.HandleLog;

await UniTask.WaitWhile(() => true, cancellationToken: token);
await UniTask.WaitWhile(() => true, cancellationToken: cancellationToken);
}
finally
{
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Agents/OneTimeAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static void ResetExecutedFlag()
}

/// <inheritdoc />
public override async UniTask Run(CancellationToken token)
public override async UniTask Run(CancellationToken cancellationToken)
{
if (WasExecuted)
{
Expand All @@ -50,7 +50,7 @@ public override async UniTask Run(CancellationToken token)
agent.Random = Random; // This Agent does not consume pseudo-random numbers, so passed on as is.
try
{
await agent.Run(token);
await agent.Run(cancellationToken);
}
finally
{
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Agents/ParallelCompositeAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace DeNA.Anjin.Agents
public class ParallelCompositeAgent : AbstractCompositeAgent
{
/// <inheritdoc />
public override async UniTask Run(CancellationToken token)
public override async UniTask Run(CancellationToken cancellationToken)
{
Logger.Log($"Enter {this.name}.Run()");

Expand All @@ -26,7 +26,7 @@ public override async UniTask Run(CancellationToken token)
{
agent.Logger = Logger;
agent.Random = RandomFactory.CreateRandom();
tasks.Add(agent.Run(token));
tasks.Add(agent.Run(cancellationToken));
}

try
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Agents/RepeatAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class RepeatAgent : AbstractAgent
/// <inheritdoc />
[SuppressMessage("Blocker Bug", "S2190:Recursion should not be infinite")]
[SuppressMessage("ReSharper", "FunctionNeverReturns")]
public override async UniTask Run(CancellationToken token)
public override async UniTask Run(CancellationToken cancellationToken)
{
Logger.Log($"Enter {this.name}.Run()");

Expand All @@ -32,7 +32,7 @@ public override async UniTask Run(CancellationToken token)
{
while (true) // Note: This agent is not terminate myself
{
await agent.Run(token);
await agent.Run(cancellationToken);
}
}
finally
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Agents/SerialCompositeAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace DeNA.Anjin.Agents
public class SerialCompositeAgent : AbstractCompositeAgent
{
/// <inheritdoc />
public override async UniTask Run(CancellationToken token)
public override async UniTask Run(CancellationToken cancellationToken)
{
Logger.Log($"Enter {this.name}.Run()");

Expand All @@ -25,7 +25,7 @@ public override async UniTask Run(CancellationToken token)
{
agent.Logger = Logger;
agent.Random = RandomFactory.CreateRandom();
await agent.Run(token);
await agent.Run(cancellationToken);
}
}
finally
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Agents/TerminateAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public ExitCode ExitCode
public string exitMessage = "Terminated by TerminateAgent";

/// <inheritdoc/>
public override async UniTask Run(CancellationToken token)
public override async UniTask Run(CancellationToken cancellationToken)
{
try
{
Expand Down
7 changes: 4 additions & 3 deletions Runtime/Agents/TimeBombAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,16 @@ private void HandleDefuseMessage(string logString, string stackTrace, LogType ty
}

/// <inheritdoc />
public override async UniTask Run(CancellationToken token)
public override async UniTask Run(CancellationToken cancellationToken)
{
Logger.Log($"Enter {this.name}.Run()");

try
{
using (_agentCts = new CancellationTokenSource()) // To cancel only the Working Agent.
{
using (var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(token, _agentCts.Token))
using (var linkedCts =
CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, _agentCts.Token))
{
try
{
Expand All @@ -119,7 +120,7 @@ public override async UniTask Run(CancellationToken token)
}
catch (OperationCanceledException)
{
if (token.IsCancellationRequested) // The parent was cancelled.
if (cancellationToken.IsCancellationRequested) // The parent was cancelled.
{
throw;
}
Expand Down
6 changes: 3 additions & 3 deletions Runtime/Agents/UGUIEmergencyExitAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class UGUIEmergencyExitAgent : AbstractAgent
private IScreenshotFilenameStrategy _filenameStrategy;

/// <inheritdoc />
public override async UniTask Run(CancellationToken token)
public override async UniTask Run(CancellationToken cancellationToken)
{
Logger.Log($"Enter {this.name}.Run()");
this._filenameStrategy = new TwoTieredCounterStrategy(this.name);
Expand All @@ -58,11 +58,11 @@ public override async UniTask Run(CancellationToken token)
{
if (selectables[i].TryGetComponent<EmergencyExitAnnotation>(out var emergencyExit))
{
await ClickEmergencyExitButton(emergencyExit, token);
await ClickEmergencyExitButton(emergencyExit, cancellationToken);
}
}

await UniTask.Delay(intervalMillis, ignoreTimeScale: true, cancellationToken: token);
await UniTask.Delay(intervalMillis, ignoreTimeScale: true, cancellationToken: cancellationToken);
}
}
finally
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Agents/UGUIMonkeyAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public class UGUIMonkeyAgent : AbstractAgent
ScreenCapture.StereoScreenCaptureMode.LeftEye;

/// <inheritdoc />
public override async UniTask Run(CancellationToken token)
public override async UniTask Run(CancellationToken cancellationToken)
{
Logger.Log($"Enter {this.name}.Run()");

Expand Down Expand Up @@ -136,7 +136,7 @@ public override async UniTask Run(CancellationToken token)

try
{
await Monkey.Run(config, token);
await Monkey.Run(config, cancellationToken);
}
catch (TimeoutException e)
{
Expand Down
8 changes: 4 additions & 4 deletions Runtime/Agents/UGUIPlaybackAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class UGUIPlaybackAgent : AbstractAgent
public TextAsset recordedJson;

/// <inheritdoc />
public override async UniTask Run(CancellationToken token)
public override async UniTask Run(CancellationToken cancellationToken)
{
try
{
Expand All @@ -40,7 +40,7 @@ public override async UniTask Run(CancellationToken token)
throw new NullReferenceException("recordingJson is null");
}

await Play(recordedJson, token);
await Play(recordedJson, cancellationToken);
// Note: If playback is not possible, AQA will output a LogError and exit. You must handle LogError with the ErrorHandlerAgent.
}
finally
Expand Down Expand Up @@ -85,7 +85,7 @@ private static void StoreScreenshots(string dst)
}
}

private static IEnumerator Play(TextAsset recordingJson, CancellationToken token)
private static IEnumerator Play(TextAsset recordingJson, CancellationToken cancellationToken)
{
if (RecordedPlaybackController.Exists())
{
Expand All @@ -100,7 +100,7 @@ private static IEnumerator Play(TextAsset recordingJson, CancellationToken token
// Use the fact that RecordedPlaybackController._instance becomes null when playback is finished.
// This behavior is from Automated QA v0.8.1. May change in the future
{
token.ThrowIfCancellationRequested();
cancellationToken.ThrowIfCancellationRequested();
yield return null;
}
// Note: Driver.Perform.PlayRecording()を使わない理由は以下
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Autopilot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private void Start()

_logger = _settings.LoggerAsset.Logger;
// Note: Set a default logger if no logger settings. see: AutopilotSettings.Initialize method.
_logger.Log("Launching Autopilot");
_logger.Log("Launching Autopilot...");

if (!int.TryParse(_settings.randomSeed, out var seed))
{
Expand Down
14 changes: 8 additions & 6 deletions Runtime/Launcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ public static class Launcher
/// Launch autopilot from Play Mode tests or runtime (e.g., debug menu).
/// </summary>
/// <param name="settings">Autopilot settings</param>
/// <param name="token">Task cancellation token</param>
public static async UniTask LaunchAutopilotAsync(AutopilotSettings settings, CancellationToken token = default)
/// <param name="cancellationToken">Task cancellation token</param>
public static async UniTask LaunchAutopilotAsync(AutopilotSettings settings,
CancellationToken cancellationToken = default)
{
#if UNITY_EDITOR
if (!EditorApplication.isPlaying)
Expand All @@ -51,7 +52,7 @@ public static async UniTask LaunchAutopilotAsync(AutopilotSettings settings, Can
state.settings = settings;
LaunchAutopilot().Forget();

await UniTask.WaitUntil(() => !state.IsRunning, cancellationToken: token);
await UniTask.WaitUntil(() => !state.IsRunning, cancellationToken: cancellationToken);

#if UNITY_INCLUDE_TESTS
// Launch from Play Mode tests
Expand All @@ -73,8 +74,9 @@ public static async UniTask LaunchAutopilotAsync(AutopilotSettings settings, Can
/// Launch autopilot from Play Mode tests or runtime (e.g., debug menu).
/// </summary>
/// <param name="settingsPath">Asset file path for autopilot settings. When running the player, it reads from <c>Resources</c></param>
/// <param name="token">Task cancellation token</param>
public static async UniTask LaunchAutopilotAsync(string settingsPath, CancellationToken token = default)
/// <param name="cancellationToken">Task cancellation token</param>
public static async UniTask LaunchAutopilotAsync(string settingsPath,
CancellationToken cancellationToken = default)
{
#if UNITY_EDITOR
var settings = AssetDatabase.LoadAssetAtPath<AutopilotSettings>(settingsPath);
Expand All @@ -86,7 +88,7 @@ public static async UniTask LaunchAutopilotAsync(string settingsPath, Cancellati
throw new ArgumentException($"Autopilot settings not found: {settingsPath}");
}

await LaunchAutopilotAsync(settings, token);
await LaunchAutopilotAsync(settings, cancellationToken);
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions Tests/Runtime/Agents/DoNothingAgentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public async Task Run_cancelTask_stopAgent()
agent.lifespanSec = 0; // Expect indefinite execution

var gameObject = new GameObject();
var token = gameObject.GetCancellationTokenOnDestroy();
var task = agent.Run(token);
var cancellationToken = gameObject.GetCancellationTokenOnDestroy();
var task = agent.Run(cancellationToken);
await UniTask.NextFrame();

Object.DestroyImmediate(gameObject);
Expand All @@ -48,8 +48,8 @@ public async Task Run_lifespanPassed_stopAgent()

using (var cancellationTokenSource = new CancellationTokenSource())
{
var token = cancellationTokenSource.Token;
var task = agent.Run(token);
var cancellationToken = cancellationTokenSource.Token;
var task = agent.Run(cancellationToken);
await UniTask.Delay(2000); // Consider overhead

Assert.That(task.Status, Is.EqualTo(UniTaskStatus.Succeeded));
Expand Down
8 changes: 4 additions & 4 deletions Tests/Runtime/Agents/OneTimeAgentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public async Task Run_cancelTask_stopAgent()
agent.agent = childAgent;

var gameObject = new GameObject();
var token = gameObject.GetCancellationTokenOnDestroy();
var task = agent.Run(token);
var cancellationToken = gameObject.GetCancellationTokenOnDestroy();
var task = agent.Run(cancellationToken);
await UniTask.NextFrame();

Object.DestroyImmediate(gameObject);
Expand All @@ -65,8 +65,8 @@ public async Task Run_markWasExecuted()

using (var cancellationTokenSource = new CancellationTokenSource())
{
var token = cancellationTokenSource.Token;
var task = agent.Run(token);
var cancellationToken = cancellationTokenSource.Token;
var task = agent.Run(cancellationToken);
await UniTask.Delay(500); // Consider overhead

Assert.That(task.Status, Is.EqualTo(UniTaskStatus.Succeeded));
Expand Down
8 changes: 4 additions & 4 deletions Tests/Runtime/Agents/ParallelCompositeAgentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public async Task Run_cancelTask_stopAgent()
agent.agents = new List<AbstractAgent>() { firstChildAgent, secondChildAgent, lastChildAgent };

var gameObject = new GameObject();
var token = gameObject.GetCancellationTokenOnDestroy();
var task = agent.Run(token);
var cancellationToken = gameObject.GetCancellationTokenOnDestroy();
var task = agent.Run(cancellationToken);
await UniTask.NextFrame();

Object.DestroyImmediate(gameObject);
Expand Down Expand Up @@ -75,8 +75,8 @@ public async Task Run_lifespanPassed_stopAgent()

using (var cancellationTokenSource = new CancellationTokenSource())
{
var token = cancellationTokenSource.Token;
var task = agent.Run(token);
var cancellationToken = cancellationTokenSource.Token;
var task = agent.Run(cancellationToken);
await UniTask.Delay(1000); // Consider overhead

Assert.That(task.Status, Is.EqualTo(UniTaskStatus.Succeeded));
Expand Down
12 changes: 6 additions & 6 deletions Tests/Runtime/Agents/RepeatAgentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public async Task Run_cancelTask_stopAgent()
agent.agent = childAgent;

var gameObject = new GameObject();
var token = gameObject.GetCancellationTokenOnDestroy();
var task = agent.Run(token);
var cancellationToken = gameObject.GetCancellationTokenOnDestroy();
var task = agent.Run(cancellationToken);
await UniTask.NextFrame();

Object.DestroyImmediate(gameObject);
Expand All @@ -61,8 +61,8 @@ public async Task Run_childAgentRunRepeating()
agent.agent = childAgent;

var gameObject = new GameObject();
var token = gameObject.GetCancellationTokenOnDestroy();
var task = agent.Run(token);
var cancellationToken = gameObject.GetCancellationTokenOnDestroy();
var task = agent.Run(cancellationToken);
await UniTask.Delay(500);

Object.DestroyImmediate(gameObject);
Expand All @@ -87,8 +87,8 @@ public async Task Run_setLoggerAndRandomInstanceToChildAgent()
agent.agent = childAgent;

var gameObject = new GameObject();
var token = gameObject.GetCancellationTokenOnDestroy();
var task = agent.Run(token);
var cancellationToken = gameObject.GetCancellationTokenOnDestroy();
var task = agent.Run(cancellationToken);
await UniTask.Delay(500);

Object.DestroyImmediate(gameObject);
Expand Down
Loading
Loading