Skip to content

Commit

Permalink
Add await for color check to avoid crash (#11022)
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWeen authored and rmarinho committed Nov 2, 2022
1 parent 8f7ca1c commit f32cbd5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ int GetPlatformMaxLines(LabelHandler labelHandler) =>

Task ValidateHasColor(Label label, Color color, Action action = null)
{
return InvokeOnMainThreadAsync(() =>
return InvokeOnMainThreadAsync(async () =>
{
var labelHandler = CreateHandler<LabelHandler>(label);
action?.Invoke();
labelHandler.PlatformView.AssertContainsColor(color);
await labelHandler.PlatformView.AssertContainsColor(color);
});
}
}
Expand Down
17 changes: 14 additions & 3 deletions src/Core/tests/DeviceTests/Services/Dispatching/DispatcherTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,21 +183,32 @@ public Task CreateTimerRepeatingRepeats() =>
timer.Interval = TimeSpan.FromMilliseconds(200);
timer.IsRepeating = true;

TaskCompletionSource taskCompletionSource = new TaskCompletionSource();

timer.Tick += (_, _) =>
{
Assert.True(timer.IsRunning, "Timer was not running DURING the tick.");
ticks++;

if (ticks > 1)
taskCompletionSource.SetResult();
};

timer.Start();

Assert.True(timer.IsRunning, "Timer was not running AFTER the tick.");

// Give it time to repeat at least once
await Task.Delay(TimeSpan.FromSeconds(1));
try
{
await taskCompletionSource.Task.WaitAsync(TimeSpan.FromSeconds(5)).ConfigureAwait(false);
}
catch (TaskCanceledException)
{
// If the task is cancelled we want it to just fall through to the assert
}

// If it's repeating, ticks will be greater than 1
Assert.True(ticks > 1);
Assert.True(ticks > 1, $"# of Ticks: {ticks}, expected > 1");
});

class TimerDisposer : IDisposable
Expand Down

0 comments on commit f32cbd5

Please sign in to comment.