You've already forked linux-packaging-mono
Imported Upstream version 5.8.0.22
Former-commit-id: df344e34b07851d296efb3e6604c8db42b6f7aa3
This commit is contained in:
parent
5f4a27cc8a
commit
7d05485754
@@ -27,6 +27,7 @@
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using NUnit.Framework;
|
||||
|
||||
@@ -91,8 +92,8 @@ namespace MonoTests.System.Threading
|
||||
else
|
||||
ThreadPool.QueueUserWorkItem (_ => { Interlocked.Increment (ref sum); Interlocked.Increment (ref total); });
|
||||
}
|
||||
var start = DateTime.Now;
|
||||
while ((total != n || sum != 0) && (DateTime.Now - start).TotalSeconds < 60)
|
||||
var sw = Stopwatch.StartNew ();
|
||||
while ((total != n || sum != 0) && sw.Elapsed.TotalSeconds < 60)
|
||||
Thread.Sleep (1000);
|
||||
Assert.IsTrue (total == n, "#1");
|
||||
Assert.IsTrue (sum == 0, "#2");
|
||||
@@ -160,7 +161,7 @@ namespace MonoTests.System.Threading
|
||||
public void GetAvailableThreads ()
|
||||
{
|
||||
ManualResetEvent mre = new ManualResetEvent (false);
|
||||
DateTime start = DateTime.Now;
|
||||
var sw = Stopwatch.StartNew ();
|
||||
int i, workerThreads, completionPortThreads;
|
||||
|
||||
try {
|
||||
@@ -173,7 +174,7 @@ namespace MonoTests.System.Threading
|
||||
|
||||
Console.WriteLine ("workerThreads = {0}, completionPortThreads = {1}", workerThreads, completionPortThreads);
|
||||
|
||||
if ((DateTime.Now - start).TotalSeconds >= 10)
|
||||
if (sw.Elapsed.TotalSeconds >= 10)
|
||||
Assert.Fail ("did not reach 0 available threads");
|
||||
|
||||
ThreadPool.QueueUserWorkItem (GetAvailableThreads_Callback, mre);
|
||||
|
@@ -1349,9 +1349,9 @@ namespace MonoTests.System.Threading
|
||||
|
||||
public static void WhileAlive (Thread t, bool alive, string s)
|
||||
{
|
||||
DateTime ti = DateTime.Now;
|
||||
var sw = SD.Stopwatch.StartNew ();
|
||||
while (t.IsAlive == alive) {
|
||||
if ((DateTime.Now - ti).TotalSeconds > 10) {
|
||||
if (sw.Elapsed.TotalSeconds > 10) {
|
||||
if (alive) Assert.Fail ("Timeout while waiting for not alive state. " + s);
|
||||
else Assert.Fail ("Timeout while waiting for alive state. " + s);
|
||||
}
|
||||
@@ -1360,12 +1360,12 @@ namespace MonoTests.System.Threading
|
||||
|
||||
public static bool WhileAliveOrStop (Thread t, bool alive, string s)
|
||||
{
|
||||
DateTime ti = DateTime.Now;
|
||||
var sw = SD.Stopwatch.StartNew ();
|
||||
while (t.IsAlive == alive) {
|
||||
if (t.ThreadState == ThreadState.Stopped)
|
||||
return false;
|
||||
|
||||
if ((DateTime.Now - ti).TotalSeconds > 10) {
|
||||
if (sw.Elapsed.TotalSeconds > 10) {
|
||||
if (alive) Assert.Fail ("Timeout while waiting for not alive state. " + s);
|
||||
else Assert.Fail ("Timeout while waiting for alive state. " + s);
|
||||
}
|
||||
|
@@ -28,6 +28,7 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
@@ -558,8 +559,8 @@ namespace MonoTests.System.Threading {
|
||||
|
||||
Thread.Sleep (10); // wait a bit so we enter mre.WaitOne
|
||||
|
||||
DateTime end = DateTime.Now.AddMilliseconds (500);
|
||||
while (DateTime.Now < end) {
|
||||
var sw = Stopwatch.StartNew ();
|
||||
while (sw.ElapsedMilliseconds <= 500) {
|
||||
thread.Suspend ();
|
||||
thread.Resume ();
|
||||
}
|
||||
@@ -588,8 +589,8 @@ namespace MonoTests.System.Threading {
|
||||
|
||||
Thread.Sleep (10); // wait a bit so we enter WaitHandle.WaitAny ({mre1, mre2})
|
||||
|
||||
DateTime end = DateTime.Now.AddMilliseconds (500);
|
||||
while (DateTime.Now < end) {
|
||||
var sw = Stopwatch.StartNew ();
|
||||
while (sw.ElapsedMilliseconds <= 500) {
|
||||
thread.Suspend ();
|
||||
thread.Resume ();
|
||||
}
|
||||
@@ -618,8 +619,8 @@ namespace MonoTests.System.Threading {
|
||||
|
||||
Thread.Sleep (10); // wait a bit so we enter WaitHandle.WaitAll ({mre1, mre2})
|
||||
|
||||
DateTime end = DateTime.Now.AddMilliseconds (500);
|
||||
while (DateTime.Now < end) {
|
||||
var sw = Stopwatch.StartNew ();
|
||||
while (sw.ElapsedMilliseconds <= 500) {
|
||||
thread.Suspend ();
|
||||
thread.Resume ();
|
||||
}
|
||||
@@ -628,6 +629,19 @@ namespace MonoTests.System.Threading {
|
||||
}
|
||||
}
|
||||
#endif // MONO_FEATURE_THREAD_SUSPEND_RESUME
|
||||
|
||||
[Test]
|
||||
public static void SignalAndWait()
|
||||
{
|
||||
using (var eventToSignal = new AutoResetEvent (false))
|
||||
using (var eventToWait = new AutoResetEvent (false))
|
||||
{
|
||||
eventToWait.Set ();
|
||||
|
||||
Assert.IsTrue (WaitHandle.SignalAndWait (eventToSignal, eventToWait), "#1");
|
||||
Assert.IsTrue (eventToSignal.WaitOne (), "#2");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user