public void TestAsyncLoadComplete() { AddStep("add box", () => Child = box = new AsyncPerformingBox(true)); AddAssert("not spun", () => box.Rotation == 0); AddStep("trigger", () => box.ReleaseAsyncLoadCompleteLock()); AddUntilStep("has spun", () => box.Rotation == 180); }
public void TestAsyncInsideUpdate() { int updateCount = 0; AddStep("add box", () => { updateCount = 0; Child = box = new AsyncPerformingBox(false); }); AddUntilStep("has spun", () => box.Rotation == 180); AddStep("update with async", () => { #pragma warning disable 4014 box.OnUpdate += _ => asyncAction(); #pragma warning restore 4014 async Task asyncAction() { updateCount++; await box.PerformAsyncWait().ConfigureAwait(true); box.RotateTo(0, 500); } }); AddUntilStep("is running updates", () => updateCount > 5); AddStep("trigger", () => box.ReleaseAsyncLoadCompleteLock()); AddUntilStep("has spun", () => box.Rotation == 0); }
public void TestAsyncUsesScheduler() { int initialTasksRun = 0; AddStep("get initial run count", () => initialTasksRun = syncContext.TotalTasksRun); AddStep("add box", () => Child = box = new AsyncPerformingBox(true)); AddAssert("no tasks run", () => syncContext.TotalTasksRun == initialTasksRun); AddStep("trigger", () => box.ReleaseAsyncLoadCompleteLock()); AddUntilStep("one new task run", () => syncContext.TotalTasksRun == initialTasksRun + 1); }
public void TestNoAsyncDoesntUseScheduler() { int initialTasksRun = 0; AddStep("get initial run count", () => initialTasksRun = syncContext.TotalTasksRun); AddStep("add box", () => Child = box = new AsyncPerformingBox(false)); AddAssert("no tasks run", () => syncContext.TotalTasksRun == initialTasksRun); AddStep("trigger", () => box.ReleaseAsyncLoadCompleteLock()); AddAssert("no tasks run", () => syncContext.TotalTasksRun == initialTasksRun); }
public void TestExecutionMode() { AddStep("add box", () => Child = box = new AsyncPerformingBox(true)); AddAssert("not spun", () => box.Rotation == 0); AddStep("toggle execution mode", () => toggleExecutionMode()); AddStep("trigger", () => box.ReleaseAsyncLoadCompleteLock()); AddUntilStep("has spun", () => box.Rotation == 180); AddStep("revert execution mode", () => toggleExecutionMode()); void toggleExecutionMode() { var executionMode = config.GetBindable <ExecutionMode>(FrameworkSetting.ExecutionMode); executionMode.Value = executionMode.Value == ExecutionMode.MultiThreaded ? ExecutionMode.SingleThread : ExecutionMode.MultiThreaded; } }
public void TestAsyncInsideSchedule() { AddStep("add box", () => Child = box = new AsyncPerformingBox(false)); AddUntilStep("has spun", () => box.Rotation == 180); AddStep("schedule with async", () => { #pragma warning disable 4014 // We may want to give `Schedule` a `Task` accepting overload in the future. box.Schedule(() => asyncScheduledAction()); #pragma warning restore 4014 async Task asyncScheduledAction() { await box.PerformAsyncWait().ConfigureAwait(true); box.RotateTo(0, 500); } }); AddStep("trigger", () => box.ReleaseAsyncLoadCompleteLock()); AddUntilStep("has spun", () => box.Rotation == 0); }