Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThays Grazia <thaystg@gmail.com>2018-12-13 19:50:06 +0300
committerGitHub <noreply@github.com>2018-12-13 19:50:06 +0300
commit05188e03f9f6453489dd706ca1ad61b997ccd25c (patch)
treef22412ecbf094a53ac77fc25b0696ad6207f538b /mcs/class/Mono.Debugger.Soft
parenta3ef7c874ee931c0c44175043fa06ba4fc5ff586 (diff)
[debugger] Fix test StepOutAsync (#12032)
* The problem with this flaky issue was the timing of processing of the async tasks, as it was executed in background threads it was not possible to reach the end of execution because all the foreground threads exit earlier. The solution creates a TaskScheduler that ensure that the thread that will execute the task will be a foreground thread and then the test always works. Fixes #6997
Diffstat (limited to 'mcs/class/Mono.Debugger.Soft')
-rw-r--r--mcs/class/Mono.Debugger.Soft/Test/dtest-app.cs73
-rw-r--r--mcs/class/Mono.Debugger.Soft/Test/dtest.cs6
2 files changed, 73 insertions, 6 deletions
diff --git a/mcs/class/Mono.Debugger.Soft/Test/dtest-app.cs b/mcs/class/Mono.Debugger.Soft/Test/dtest-app.cs
index a217648d87b..9f1f31244c3 100644
--- a/mcs/class/Mono.Debugger.Soft/Test/dtest-app.cs
+++ b/mcs/class/Mono.Debugger.Soft/Test/dtest-app.cs
@@ -13,6 +13,7 @@ using System.Threading.Tasks;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
+using System.Collections.Concurrent;
#if !MOBILE
using MonoTests.Helpers;
#endif
@@ -221,6 +222,65 @@ class TestIfaces : ITest
}
}
+public sealed class DebuggerTaskScheduler : TaskScheduler, IDisposable
+{
+ private readonly BlockingCollection<Task> _tasks = new BlockingCollection<Task>();
+ private readonly List<Thread> _threads;
+ private readonly Thread mainThread = null;
+ public DebuggerTaskScheduler(int countThreads)
+ {
+ _threads = Enumerable.Range(0, countThreads).Select(i =>
+ {
+ Thread t = new Thread(() =>
+ {
+ foreach (var task in _tasks.GetConsumingEnumerable())
+ {
+ TryExecuteTask(task);
+ }
+ });
+ //the new task will be executed by a foreground thread ensuring that it will be executed ultil the end.
+ t.IsBackground = false;
+ t.Start();
+ return t;
+
+ }).ToList();
+ }
+
+ /// <inheritdoc />
+ protected override void QueueTask(Task task)
+ {
+ _tasks.Add(task);
+ }
+
+ /// <inheritdoc />
+ public override int MaximumConcurrencyLevel
+ {
+ get
+ {
+ return _threads.Count;
+ }
+ }
+
+ /// <inheritdoc />
+ public void Dispose()
+ {
+ // Indicate that no new tasks will be coming in
+ _tasks.CompleteAdding();
+ }
+
+ /// <inheritdoc />
+ protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
+ {
+ return false;
+ }
+
+ /// <inheritdoc />
+ protected override IEnumerable<Task> GetScheduledTasks()
+ {
+ return _tasks;
+ }
+}
+
class TestIfaces<T> : ITest<T>
{
void ITest<T>.Foo () {
@@ -344,9 +404,7 @@ public class Tests : TestsBase, ITest2
return 0;
}
if (args.Length > 0 && args [0] == "step-out-void-async") {
- var wait = new ManualResetEvent (false);
- step_out_void_async (wait);
- wait.WaitOne ();//Don't exist until step_out_void_async is executed...
+ run_step_out_void_async();
return 0;
}
assembly_load ();
@@ -1782,6 +1840,15 @@ public class Tests : TestsBase, ITest2
{
UninitializedClass.Call();//Breakpoint here and step in
}
+
+ public static void run_step_out_void_async()
+ {
+ DebuggerTaskScheduler dts = new DebuggerTaskScheduler(2);
+ var wait = new ManualResetEvent (false);
+ step_out_void_async (wait);
+ wait.WaitOne ();//Don't exist until step_out_void_async is executed...
+ dts.Dispose();
+ }
[MethodImplAttribute (MethodImplOptions.NoInlining)]
static async void step_out_void_async (ManualResetEvent wait)
diff --git a/mcs/class/Mono.Debugger.Soft/Test/dtest.cs b/mcs/class/Mono.Debugger.Soft/Test/dtest.cs
index ccab651dee1..59aca74b936 100644
--- a/mcs/class/Mono.Debugger.Soft/Test/dtest.cs
+++ b/mcs/class/Mono.Debugger.Soft/Test/dtest.cs
@@ -4457,11 +4457,11 @@ public class DebuggerTests
e = run_until ("threadpool_bp");
var req = create_step (e);
e = step_out (); // leave threadpool_bp
+
e = step_out (); // leave threadpool_io
}
[Test]
- [Category("NotWorking")] // flaky, see https://github.com/mono/mono/issues/6997
public void StepOutAsync () {
vm.Detach ();
Start (new string [] { dtest_app_path, "step-out-void-async" });
@@ -4475,8 +4475,8 @@ public class DebuggerTests
vm.Resume ();
var e3 = GetNextEvent ();
//after step-out from async void, execution should continue
- //and runtime should exit
- Assert.IsTrue (e3 is VMDeathEvent, e3.GetType().FullName);
+ //and runtime should Step
+ Assert.IsTrue (e3 is StepEvent, e3.GetType().FullName);
vm = null;
}