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