-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
IsInvokeRequiredRaceCondition.cs
69 lines (57 loc) · 1.48 KB
/
IsInvokeRequiredRaceCondition.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System.Collections.Generic;
using System.Threading.Tasks;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif
namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[NUnit.Framework.Category(Core.UITests.UITestCategories.UwpIgnore)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.None, 0, "Device.IsInvokeRequired race condition causes crash")]
public class IsInvokeRequiredRaceCondition : TestContentPage
{
protected override void Init()
{
var button = new Button
{
AutomationId = "crashButton",
Text = "Start Test"
};
var success = new Label { Text = "Success", IsVisible = false, AutomationId = "successLabel" };
var instructions = new Label { Text = "Click the Start Test button. " };
Content = new StackLayout
{
HorizontalOptions = LayoutOptions.Fill,
VerticalOptions = LayoutOptions.Fill,
Children = { instructions, success, button }
};
button.Clicked += async (sender, args) =>
{
await Task.WhenAll(GenerateTasks());
success.IsVisible = true;
};
}
List<Task> GenerateTasks()
{
var result = new List<Task>();
for (int n = 0; n < 1000; n++)
{
result.Add(Task.Run(() => { var t = Device.IsInvokeRequired; } ));
}
return result;
}
#if UITEST
[Test]
public void ShouldNotCrash()
{
RunningApp.Tap(q => q.Marked("crashButton"));
RunningApp.WaitForElement(q => q.Marked("successLabel"));
}
#endif
}
}