Add self-test for framework task scheduling

This commit is contained in:
goaaats 2025-04-03 00:32:37 +02:00
parent 810611e086
commit ca438b6e69
2 changed files with 98 additions and 34 deletions

View file

@ -22,40 +22,40 @@ internal class SelfTestWindow : Window
private static readonly ModuleLog Log = new("AGING");
private readonly List<ISelfTestStep> steps =
new()
{
new LoginEventSelfTestStep(),
new WaitFramesSelfTestStep(1000),
new EnterTerritorySelfTestStep(148, "Central Shroud"),
new ItemPayloadSelfTestStep(),
new ContextMenuSelfTestStep(),
new NamePlateSelfTestStep(),
new ActorTableSelfTestStep(),
new FateTableSelfTestStep(),
new AetheryteListSelfTestStep(),
new ConditionSelfTestStep(),
new ToastSelfTestStep(),
new TargetSelfTestStep(),
new KeyStateSelfTestStep(),
new GamepadStateSelfTestStep(),
new ChatSelfTestStep(),
new HoverSelfTestStep(),
new LuminaSelfTestStep<Item>(true),
new LuminaSelfTestStep<Level>(true),
new LuminaSelfTestStep<Lumina.Excel.Sheets.Action>(true),
new LuminaSelfTestStep<Quest>(true),
new LuminaSelfTestStep<TerritoryType>(false),
new AddonLifecycleSelfTestStep(),
new PartyFinderSelfTestStep(),
new HandledExceptionSelfTestStep(),
new DutyStateSelfTestStep(),
new GameConfigSelfTestStep(),
new MarketBoardSelfTestStep(),
new SheetRedirectResolverSelfTestStep(),
new NounProcessorSelfTestStep(),
new SeStringEvaluatorSelfTestStep(),
new LogoutEventSelfTestStep(),
};
[
new LoginEventSelfTestStep(),
new WaitFramesSelfTestStep(1000),
new FrameworkTaskSchedulerSelfTestStep(),
new EnterTerritorySelfTestStep(148, "Central Shroud"),
new ItemPayloadSelfTestStep(),
new ContextMenuSelfTestStep(),
new NamePlateSelfTestStep(),
new ActorTableSelfTestStep(),
new FateTableSelfTestStep(),
new AetheryteListSelfTestStep(),
new ConditionSelfTestStep(),
new ToastSelfTestStep(),
new TargetSelfTestStep(),
new KeyStateSelfTestStep(),
new GamepadStateSelfTestStep(),
new ChatSelfTestStep(),
new HoverSelfTestStep(),
new LuminaSelfTestStep<Item>(true),
new LuminaSelfTestStep<Level>(true),
new LuminaSelfTestStep<Lumina.Excel.Sheets.Action>(true),
new LuminaSelfTestStep<Quest>(true),
new LuminaSelfTestStep<TerritoryType>(false),
new AddonLifecycleSelfTestStep(),
new PartyFinderSelfTestStep(),
new HandledExceptionSelfTestStep(),
new DutyStateSelfTestStep(),
new GameConfigSelfTestStep(),
new MarketBoardSelfTestStep(),
new SheetRedirectResolverSelfTestStep(),
new NounProcessorSelfTestStep(),
new SeStringEvaluatorSelfTestStep(),
new LogoutEventSelfTestStep()
];
private readonly Dictionary<int, (SelfTestStepResult Result, TimeSpan? Duration)> testIndexToResult = new();

View file

@ -0,0 +1,64 @@
using System.Threading.Tasks;
using Dalamud.Game;
using Dalamud.Utility;
namespace Dalamud.Interface.Internal.Windows.SelfTest.Steps;
/// <summary>
/// Test setup for Framework task scheduling.
/// </summary>
internal class FrameworkTaskSchedulerSelfTestStep : ISelfTestStep
{
private bool passed = false;
private Task? task;
/// <inheritdoc/>
public string Name => "Test Framework Task Scheduler";
/// <inheritdoc/>
public SelfTestStepResult RunStep()
{
var framework = Service<Framework>.Get();
this.task ??= Task.Run(async () =>
{
ThreadSafety.AssertNotMainThread();
await framework.RunOnTick(async () =>
{
ThreadSafety.AssertMainThread();
await Task.Delay(100);
// TODO: We used to be scheduled back to the framework thread here. Is that by design?
//ThreadSafety.AssertMainThread();
ThreadSafety.AssertNotMainThread();
}).ConfigureAwait(false);
ThreadSafety.AssertNotMainThread();
await framework.RunOnTick(() =>
{
ThreadSafety.AssertMainThread();
});
ThreadSafety.AssertMainThread();
this.passed = true;
});
if (this.task is { IsFaulted: true } or { IsCanceled: true })
{
return SelfTestStepResult.Fail;
}
return this.passed ? SelfTestStepResult.Pass : SelfTestStepResult.Waiting;
}
/// <inheritdoc/>
public void CleanUp()
{
this.passed = false;
this.task = null;
}
}