You've already forked linux-packaging-mono
Imported Upstream version 4.3.2.467
Former-commit-id: 9c2cb47f45fa221e661ab616387c9cda183f283d
This commit is contained in:
@@ -27,7 +27,6 @@
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if NET_4_0
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
@@ -66,9 +65,11 @@ namespace MonoTests.System.Threading
|
||||
{
|
||||
int called = 0;
|
||||
var cts = new CancellationTokenSource ();
|
||||
cts.Token.Register (() => called++);
|
||||
var mre = new ManualResetEvent(false);
|
||||
cts.Token.Register (() => { called++; mre.Set (); });
|
||||
cts.CancelAfter (20);
|
||||
Thread.Sleep (50);
|
||||
|
||||
Assert.IsTrue(mre.WaitOne (1000), "Should be cancelled in ~20ms");
|
||||
Assert.AreEqual (1, called, "#1");
|
||||
}
|
||||
|
||||
@@ -489,5 +490,4 @@ namespace MonoTests.System.Threading
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -26,7 +26,6 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#if NET_4_0
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
@@ -105,4 +104,3 @@ namespace MonoTests.System.Threading
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@@ -26,7 +26,6 @@
|
||||
//
|
||||
//
|
||||
|
||||
#if NET_4_0
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
@@ -396,4 +395,3 @@ namespace MonoTests.System.Threading
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@@ -26,7 +26,6 @@
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if NET_4_0
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
@@ -92,5 +91,4 @@ namespace MonoTests.System.Threading
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -27,7 +27,6 @@
|
||||
//
|
||||
//
|
||||
|
||||
#if NET_4_0
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
@@ -306,4 +305,3 @@ namespace MonoTests.System.Threading
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@@ -303,7 +303,6 @@ namespace MonoTests.System.Threading {
|
||||
Assert.IsFalse (Monitor.Wait (o, SmallNegative), "Wait");
|
||||
}
|
||||
}
|
||||
#if NET_4_0
|
||||
[Test]
|
||||
public void Enter_bool ()
|
||||
{
|
||||
@@ -333,7 +332,6 @@ namespace MonoTests.System.Threading {
|
||||
Monitor.Enter (o, ref taken);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -128,7 +128,11 @@ namespace MonoTests.System.Threading
|
||||
TestUtil.WaitForNotAlive (thread1, "");
|
||||
Assert.AreEqual (100, class1.marker);
|
||||
} finally {
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
thread1.Abort ();
|
||||
#else
|
||||
thread1.Interrupt ();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,8 +154,13 @@ namespace MonoTests.System.Threading
|
||||
|
||||
Assert.AreEqual (class2.id, class2.marker);
|
||||
} finally {
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
thread1.Abort ();
|
||||
thread2.Abort ();
|
||||
#else
|
||||
thread1.Interrupt ();
|
||||
thread2.Interrupt ();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,3 @@
|
||||
#if NET_4_0
|
||||
// SemaphoreSlimTests.cs
|
||||
//
|
||||
// Copyright (c) 2008 Jérémie "Garuma" Laval
|
||||
@@ -92,4 +91,3 @@ namespace MonoTests.System.Threading
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@@ -1,4 +1,3 @@
|
||||
#if NET_4_0
|
||||
//
|
||||
// SpinLockTests.cs
|
||||
//
|
||||
@@ -156,4 +155,3 @@ namespace MonoTests.System.Threading
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@@ -69,6 +69,7 @@ namespace MonoCasTests.System.Threading {
|
||||
|
||||
// test Demand by denying the caller of the required privileges
|
||||
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
[Test]
|
||||
[SecurityPermission (SecurityAction.Deny, ControlThread = true)]
|
||||
[ExpectedException (typeof (SecurityException))]
|
||||
@@ -84,7 +85,8 @@ namespace MonoCasTests.System.Threading {
|
||||
{
|
||||
Thread.CurrentThread.Abort (new object [0]);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
[SecurityPermission (SecurityAction.Deny, ControlThread = true)]
|
||||
[ExpectedException (typeof (SecurityException))]
|
||||
@@ -101,6 +103,7 @@ namespace MonoCasTests.System.Threading {
|
||||
Thread.CurrentThread.Interrupt ();
|
||||
}
|
||||
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
[Test]
|
||||
[SecurityPermission (SecurityAction.Deny, ControlThread = true)]
|
||||
[ExpectedException (typeof (SecurityException))]
|
||||
@@ -108,7 +111,9 @@ namespace MonoCasTests.System.Threading {
|
||||
{
|
||||
Thread.ResetAbort ();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if MONO_FEATURE_THREAD_SUSPEND_RESUME
|
||||
[Test]
|
||||
[SecurityPermission (SecurityAction.Deny, ControlThread = true)]
|
||||
[ExpectedException (typeof (SecurityException))]
|
||||
@@ -124,6 +129,7 @@ namespace MonoCasTests.System.Threading {
|
||||
{
|
||||
Thread.CurrentThread.Suspend ();
|
||||
}
|
||||
#endif
|
||||
|
||||
// we use reflection to call Mutex as it's named constructors are protected by
|
||||
// a LinkDemand (which will be converted into full demand, i.e. a stack walk)
|
||||
|
@@ -1,4 +1,3 @@
|
||||
#if NET_4_0
|
||||
//
|
||||
// ThreadLazyTests.cs
|
||||
//
|
||||
@@ -194,6 +193,9 @@ namespace MonoTests.System.Threading
|
||||
}
|
||||
|
||||
[Test]
|
||||
#if MONOTOUCH
|
||||
[Category ("NotWorking")] // https://bugzilla.xamarin.com/show_bug.cgi?id=34617
|
||||
#endif
|
||||
public void DisposeOnThreadExit ()
|
||||
{
|
||||
var threadLocal = new ThreadLocal<SetMreOnFinalize>();
|
||||
@@ -215,4 +217,3 @@ namespace MonoTests.System.Threading
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@@ -98,7 +98,6 @@ namespace MonoTests.System.Threading
|
||||
Assert.IsTrue (sum == 0, "#2");
|
||||
}
|
||||
|
||||
#if NET_4_0
|
||||
event WaitCallback e;
|
||||
|
||||
[Test]
|
||||
@@ -117,7 +116,6 @@ namespace MonoTests.System.Threading
|
||||
ThreadPool.UnsafeQueueUserWorkItem (e, null);
|
||||
Assert.IsTrue (ev.Wait (3000));
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void SetAndGetMinThreads ()
|
||||
@@ -173,6 +171,8 @@ namespace MonoTests.System.Threading
|
||||
if (workerThreads == 0)
|
||||
break;
|
||||
|
||||
Console.WriteLine ("workerThreads = {0}, completionPortThreads = {1}", workerThreads, completionPortThreads);
|
||||
|
||||
if ((DateTime.Now - start).TotalSeconds >= 10)
|
||||
Assert.Fail ("did not reach 0 available threads");
|
||||
|
||||
|
@@ -13,6 +13,9 @@ using System;
|
||||
using System.Globalization;
|
||||
using System.Security.Principal;
|
||||
using System.Threading;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
using SD = System.Diagnostics;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
@@ -181,7 +184,11 @@ namespace MonoTests.System.Threading
|
||||
{
|
||||
sub_thread.Start();
|
||||
Thread.Sleep (100);
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
sub_thread.Abort();
|
||||
#else
|
||||
sub_thread.Interrupt ();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,10 +219,18 @@ namespace MonoTests.System.Threading
|
||||
thread2.Start();
|
||||
TestUtil.WaitForAlive (thread2, "wait2");
|
||||
T2ON = true;
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
thread1.Abort();
|
||||
#else
|
||||
thread1.Interrupt ();
|
||||
#endif
|
||||
TestUtil.WaitForNotAlive (thread1, "wait3");
|
||||
T1ON = false;
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
thread2.Abort();
|
||||
#else
|
||||
thread2.Interrupt ();
|
||||
#endif
|
||||
TestUtil.WaitForNotAlive (thread2, "wait4");
|
||||
T2ON = false;
|
||||
}
|
||||
@@ -325,7 +340,11 @@ namespace MonoTests.System.Threading
|
||||
C2Test test1 = new C2Test();
|
||||
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
|
||||
TestThread.Start();
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
TestThread.Abort();
|
||||
#else
|
||||
TestThread.Interrupt ();
|
||||
#endif
|
||||
try {
|
||||
TestThread.Start();
|
||||
Assert.Fail ("#2");
|
||||
@@ -340,7 +359,11 @@ namespace MonoTests.System.Threading
|
||||
}
|
||||
bool started = (TestThread.ThreadState == ThreadState.Running);
|
||||
Assert.AreEqual (started, test1.run, "#15 Thread Is not in the correct state: ");
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
TestThread.Abort();
|
||||
#else
|
||||
TestThread.Interrupt ();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,10 +379,15 @@ namespace MonoTests.System.Threading
|
||||
TestThread.Start();
|
||||
TestUtil.WaitForAlive (TestThread, "wait5");
|
||||
Assert.AreEqual (ApartmentState.MTA, TestThread.ApartmentState, "#2");
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
TestThread.Abort();
|
||||
#else
|
||||
TestThread.Interrupt ();
|
||||
#endif
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category ("NotWorking")] // setting the priority of a Thread before it is started isn't implemented in Mono yet
|
||||
public void TestPriority1()
|
||||
{
|
||||
if (is_win32 && is_mono)
|
||||
@@ -369,16 +397,22 @@ namespace MonoTests.System.Threading
|
||||
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
|
||||
try {
|
||||
TestThread.Priority=ThreadPriority.BelowNormal;
|
||||
ThreadPriority after = TestThread.Priority;
|
||||
ThreadPriority before = TestThread.Priority;
|
||||
Assert.AreEqual (ThreadPriority.BelowNormal, before, "#40 Unexpected priority before thread start: ");
|
||||
TestThread.Start();
|
||||
TestUtil.WaitForAlive (TestThread, "wait7");
|
||||
ThreadPriority before = TestThread.Priority;
|
||||
ThreadPriority after = TestThread.Priority;
|
||||
Assert.AreEqual (before, after, "#41 Unexpected Priority Change: ");
|
||||
} finally {
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
TestThread.Abort();
|
||||
#else
|
||||
TestThread.Interrupt ();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
[Test]
|
||||
[Category ("NotDotNet")] // on MS, Thread is still in AbortRequested state when Start is invoked
|
||||
public void AbortUnstarted ()
|
||||
@@ -388,6 +422,7 @@ namespace MonoTests.System.Threading
|
||||
th.Abort ();
|
||||
th.Start ();
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
[Category ("NotDotNet")] // on MS, ThreadState is immediately Stopped after Abort
|
||||
@@ -402,7 +437,11 @@ namespace MonoTests.System.Threading
|
||||
TestUtil.WaitForAliveOrStop (TestThread, "wait8");
|
||||
Assert.AreEqual (ThreadPriority.Normal, TestThread.Priority, "#43 Incorrect Priority in Started thread: ");
|
||||
} finally {
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
TestThread.Abort();
|
||||
#else
|
||||
TestThread.Interrupt ();
|
||||
#endif
|
||||
}
|
||||
Assert.AreEqual (ThreadPriority.Normal, TestThread.Priority, "#44 Incorrect Priority in Aborted thread: ");
|
||||
}
|
||||
@@ -427,7 +466,11 @@ namespace MonoTests.System.Threading
|
||||
Assert.AreEqual (ThreadPriority.Highest, TestThread.Priority, "#45E Incorrect Priority:");
|
||||
}
|
||||
finally {
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
TestThread.Abort();
|
||||
#else
|
||||
TestThread.Interrupt ();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -455,7 +498,11 @@ namespace MonoTests.System.Threading
|
||||
bool state = TestThread.IsBackground;
|
||||
Assert.IsFalse (state, "#51 IsBackground not set at the default state: ");
|
||||
} finally {
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
TestThread.Abort();
|
||||
#else
|
||||
TestThread.Interrupt ();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -468,7 +515,11 @@ namespace MonoTests.System.Threading
|
||||
try {
|
||||
TestThread.Start();
|
||||
} finally {
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
TestThread.Abort();
|
||||
#else
|
||||
TestThread.Interrupt ();
|
||||
#endif
|
||||
}
|
||||
|
||||
if (TestThread.IsAlive) {
|
||||
@@ -497,7 +548,11 @@ namespace MonoTests.System.Threading
|
||||
TestThread.Name = newname;
|
||||
Assert.AreEqual (newname, TestThread.Name, "#62 Name not set when must be set: ");
|
||||
} finally {
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
TestThread.Abort();
|
||||
#else
|
||||
TestThread.Interrupt ();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -559,7 +614,11 @@ namespace MonoTests.System.Threading
|
||||
TestThread.Start();
|
||||
TestUtil.WaitForAlive (TestThread, "wait11");
|
||||
} finally {
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
TestThread.Abort();
|
||||
#else
|
||||
TestThread.Interrupt ();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -571,7 +630,11 @@ namespace MonoTests.System.Threading
|
||||
try {
|
||||
TestThread.Start();
|
||||
} finally {
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
TestThread.Abort();
|
||||
#else
|
||||
TestThread.Interrupt ();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -587,8 +650,13 @@ namespace MonoTests.System.Threading
|
||||
thread2.Start();
|
||||
thread2.Join();
|
||||
} finally {
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
thread1.Abort();
|
||||
thread2.Abort();
|
||||
#else
|
||||
thread1.Interrupt ();
|
||||
thread2.Interrupt ();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -673,7 +741,11 @@ namespace MonoTests.System.Threading
|
||||
Assert.IsTrue (TestThread.ThreadState == ThreadState.Running || (TestThread.ThreadState & ThreadState.Unstarted) != 0,
|
||||
"#102 Wrong Thread State: " + TestThread.ThreadState.ToString ());
|
||||
} finally {
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
TestThread.Abort();
|
||||
#else
|
||||
TestThread.Interrupt ();
|
||||
#endif
|
||||
}
|
||||
|
||||
TestUtil.WaitForNotAlive (TestThread, "wait12");
|
||||
@@ -693,7 +765,11 @@ namespace MonoTests.System.Threading
|
||||
t.Start ();
|
||||
t.Join ();
|
||||
} catch {
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
t.Abort ();
|
||||
#else
|
||||
t.Interrupt ();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -708,7 +784,11 @@ namespace MonoTests.System.Threading
|
||||
t.Start ();
|
||||
t.Join ();
|
||||
} catch {
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
t.Abort ();
|
||||
#else
|
||||
t.Interrupt ();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -722,7 +802,11 @@ namespace MonoTests.System.Threading
|
||||
t.Start ();
|
||||
t.Join ();
|
||||
} catch {
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
t.Abort ();
|
||||
#else
|
||||
t.Interrupt ();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -736,12 +820,17 @@ namespace MonoTests.System.Threading
|
||||
t.Start ();
|
||||
t.Join ();
|
||||
} catch {
|
||||
#if MONO_FEATURE_THREAD_ABORT
|
||||
t.Abort ();
|
||||
#else
|
||||
t.Interrupt ();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
int counter = 0;
|
||||
|
||||
#if MONO_FEATURE_THREAD_SUSPEND_RESUME
|
||||
[Test]
|
||||
public void TestSuspend ()
|
||||
{
|
||||
@@ -765,7 +854,9 @@ namespace MonoTests.System.Threading
|
||||
TestUtil.WaitForNotAlive (t, "wait13");
|
||||
CheckIsNotRunning ("t6", t);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if MONO_FEATURE_THREAD_SUSPEND_RESUME && MONO_FEATURE_THREAD_ABORT
|
||||
[Test]
|
||||
[Category("NotDotNet")] // On MS, ThreadStateException is thrown on Abort: "Thread is suspended; attempting to abort"
|
||||
public void TestSuspendAbort ()
|
||||
@@ -796,19 +887,22 @@ namespace MonoTests.System.Threading
|
||||
|
||||
CheckIsNotRunning ("t6", t);
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void Test_Interrupt ()
|
||||
{
|
||||
ManualResetEvent mre = new ManualResetEvent (false);
|
||||
bool interruptedExceptionThrown = false;
|
||||
|
||||
ThreadPool.QueueUserWorkItem (Test_Interrupt_Worker, Thread.CurrentThread);
|
||||
|
||||
try {
|
||||
try {
|
||||
Thread.Sleep (3000);
|
||||
mre.WaitOne (3000);
|
||||
} finally {
|
||||
try {
|
||||
Thread.Sleep (0);
|
||||
mre.WaitOne (0);
|
||||
} catch (ThreadInterruptedException) {
|
||||
Assert.Fail ("ThreadInterruptedException thrown twice");
|
||||
}
|
||||
@@ -838,11 +932,12 @@ namespace MonoTests.System.Threading
|
||||
[Category ("NotDotNet")] // it crashes nunit.
|
||||
public void Test_InterruptCurrentThread ()
|
||||
{
|
||||
ManualResetEvent mre = new ManualResetEvent (false);
|
||||
bool interruptedExceptionThrown = false;
|
||||
|
||||
Thread.CurrentThread.Interrupt ();
|
||||
try {
|
||||
Thread.Sleep (0);
|
||||
mre.WaitOne (0);
|
||||
Assert.Fail ();
|
||||
} catch (ThreadInterruptedException) {
|
||||
}
|
||||
@@ -871,6 +966,7 @@ namespace MonoTests.System.Threading
|
||||
}
|
||||
}
|
||||
|
||||
#if MONO_FEATURE_MULTIPLE_APPDOMAINS
|
||||
[Test]
|
||||
public void CurrentThread_Domains ()
|
||||
{
|
||||
@@ -880,6 +976,7 @@ namespace MonoTests.System.Threading
|
||||
Assert.IsTrue (o.Run ());
|
||||
AppDomain.Unload (ad);
|
||||
}
|
||||
#endif // MONO_FEATURE_MULTIPLE_APPDOMAINS
|
||||
|
||||
void CheckIsRunning (string s, Thread t)
|
||||
{
|
||||
@@ -1272,6 +1369,17 @@ namespace MonoTests.System.Threading
|
||||
static void ThreadProc(Object stateInfo) {
|
||||
Thread.CurrentThread.Name = "My Worker";
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetStackTraces () {
|
||||
var m = typeof (Thread).GetMethod ("Mono_GetStackTraces", BindingFlags.NonPublic|BindingFlags.Static);
|
||||
if (m != null) {
|
||||
var res = (Dictionary<Thread,SD.StackTrace>)typeof (Thread).GetMethod ("Mono_GetStackTraces", BindingFlags.NonPublic|BindingFlags.Static).Invoke (null, null);
|
||||
foreach (var t in res.Keys) {
|
||||
var st = res [t].ToString ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class TestUtil
|
||||
|
@@ -29,7 +29,7 @@ namespace MonoTests.System.Threading {
|
||||
// this makes fair for the "DueTime" test since it
|
||||
// doesn't have to wait for the scheduler thread to be
|
||||
// created.
|
||||
new Timer (new TimerCallback (DoNothing), null, Timeout.Infinite, 0);
|
||||
new Timer (o => DoNothing (o), null, Timeout.Infinite, 0);
|
||||
}
|
||||
|
||||
void DoNothing (object foo)
|
||||
@@ -40,32 +40,34 @@ namespace MonoTests.System.Threading {
|
||||
public void TestDueTime ()
|
||||
{
|
||||
Bucket bucket = new Bucket();
|
||||
Timer t = new Timer (new TimerCallback (Callback), bucket, 200, Timeout.Infinite);
|
||||
Thread.Sleep (50);
|
||||
Assert.AreEqual (0, bucket.count, "#1");
|
||||
Thread.Sleep (200);
|
||||
Assert.AreEqual (1, bucket.count, "#2");
|
||||
Thread.Sleep (500);
|
||||
Assert.AreEqual (1, bucket.count, "#3");
|
||||
t.Change (10, 10);
|
||||
Thread.Sleep (1000);
|
||||
Assert.IsTrue(bucket.count > 20, "#4");
|
||||
t.Dispose ();
|
||||
|
||||
using (Timer t = new Timer (o => Callback (o), bucket, 200, Timeout.Infinite)) {
|
||||
Thread.Sleep (50);
|
||||
Assert.AreEqual (0, bucket.count, "#1");
|
||||
Thread.Sleep (200);
|
||||
Assert.AreEqual (1, bucket.count, "#2");
|
||||
Thread.Sleep (500);
|
||||
Assert.AreEqual (1, bucket.count, "#3");
|
||||
t.Change (10, 10);
|
||||
Thread.Sleep (1000);
|
||||
Assert.IsTrue(bucket.count > 20, "#4");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestChange ()
|
||||
{
|
||||
Bucket bucket = new Bucket();
|
||||
Timer t = new Timer (new TimerCallback (Callback), bucket, 10, 10);
|
||||
Thread.Sleep (500);
|
||||
int c = bucket.count;
|
||||
Assert.IsTrue (c > 20, "#1 " + c.ToString ());
|
||||
t.Change (100, 100);
|
||||
c = bucket.count;
|
||||
Thread.Sleep (500);
|
||||
Assert.IsTrue (bucket.count <= c + 20, "#2 " + c.ToString ());
|
||||
t.Dispose ();
|
||||
|
||||
using (Timer t = new Timer (o => Callback (o), bucket, 10, 10)) {
|
||||
Thread.Sleep (500);
|
||||
int c = bucket.count;
|
||||
Assert.IsTrue (c > 20, "#1 " + c.ToString ());
|
||||
t.Change (100, 100);
|
||||
c = bucket.count;
|
||||
Thread.Sleep (500);
|
||||
Assert.IsTrue (bucket.count <= c + 20, "#2 " + c.ToString ());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -73,22 +75,24 @@ namespace MonoTests.System.Threading {
|
||||
{
|
||||
Bucket bucket = new Bucket();
|
||||
|
||||
Timer t = new Timer (new TimerCallback (Callback), bucket, 0, Timeout.Infinite);
|
||||
Thread.Sleep (100);
|
||||
Assert.AreEqual (1, bucket.count, "#1");
|
||||
t.Change (0, Timeout.Infinite);
|
||||
Thread.Sleep (100);
|
||||
Assert.AreEqual (2, bucket.count, "#2");
|
||||
t.Dispose ();
|
||||
using (Timer t = new Timer (o => Callback (o), bucket, 0, Timeout.Infinite)) {
|
||||
Thread.Sleep (100);
|
||||
Assert.AreEqual (1, bucket.count, "#1");
|
||||
t.Change (0, Timeout.Infinite);
|
||||
Thread.Sleep (100);
|
||||
Assert.AreEqual (2, bucket.count, "#2");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDispose ()
|
||||
{
|
||||
Bucket bucket = new Bucket();
|
||||
Timer t = new Timer (new TimerCallback (Callback), bucket, 10, 10);
|
||||
Thread.Sleep (200);
|
||||
t.Dispose ();
|
||||
|
||||
using (Timer t = new Timer (o => Callback (o), bucket, 10, 10)) {
|
||||
Thread.Sleep (200);
|
||||
}
|
||||
|
||||
Thread.Sleep (20);
|
||||
int c = bucket.count;
|
||||
Assert.IsTrue (bucket.count > 5, "#1");
|
||||
@@ -99,7 +103,7 @@ namespace MonoTests.System.Threading {
|
||||
[Test] // bug #320950
|
||||
public void TestDispose2 ()
|
||||
{
|
||||
Timer t = new Timer (new TimerCallback (Callback), null, 10, 10);
|
||||
Timer t = new Timer (o => Callback (o), null, 10, 10);
|
||||
t.Dispose ();
|
||||
t.Dispose ();
|
||||
}
|
||||
@@ -108,9 +112,10 @@ namespace MonoTests.System.Threading {
|
||||
public void TestHeavyCreationLoad ()
|
||||
{
|
||||
Bucket b = new Bucket ();
|
||||
|
||||
for (int i = 0; i < 500; ++i)
|
||||
new Timer (new TimerCallback (Callback), b, 10,
|
||||
Timeout.Infinite);
|
||||
new Timer (o => Callback (o), b, 10, Timeout.Infinite);
|
||||
|
||||
// 1000 * 10 msec = 10,000 msec or 10 sec - if everything goes well
|
||||
// we add some slack to cope with timing issues caused by system load etc.
|
||||
for (int i = 0; i < 20; ++i) {
|
||||
@@ -118,23 +123,22 @@ namespace MonoTests.System.Threading {
|
||||
break;
|
||||
Thread.Sleep (1000);
|
||||
}
|
||||
|
||||
Assert.AreEqual (500, b.count);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestQuickDisposeDeadlockBug ()
|
||||
{
|
||||
int i = 0;
|
||||
Bucket b = new Bucket ();
|
||||
ArrayList timers = new ArrayList();
|
||||
while (i < 500) {
|
||||
Timer t = new Timer (new TimerCallback (Callback),
|
||||
b, 10, Timeout.Infinite);
|
||||
timers.Add (t);
|
||||
i++;
|
||||
t.Dispose ();
|
||||
ArrayList timers = new ArrayList (500);
|
||||
|
||||
for (int i = 0; i < 500; ++i) {
|
||||
using (Timer t = new Timer (o => Callback (o), b, 10, Timeout.Infinite)) {
|
||||
timers.Add (t);
|
||||
}
|
||||
}
|
||||
|
||||
Thread.Sleep (11 * 500);
|
||||
}
|
||||
|
||||
@@ -142,46 +146,41 @@ namespace MonoTests.System.Threading {
|
||||
public void TestInt32MaxDelay ()
|
||||
{
|
||||
Bucket b = new Bucket ();
|
||||
new Timer (new TimerCallback (Callback), b, Int32.MaxValue,
|
||||
Timeout.Infinite);
|
||||
Thread.Sleep (50);
|
||||
Assert.AreEqual (0, b.count);
|
||||
|
||||
using (new Timer (o => Callback (o), b, Int32.MaxValue, Timeout.Infinite)) {
|
||||
Thread.Sleep (50);
|
||||
Assert.AreEqual (0, b.count);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestInt32MaxPeriod ()
|
||||
{
|
||||
Bucket b = new Bucket ();
|
||||
new Timer (new TimerCallback (Callback), b, 0,
|
||||
Int32.MaxValue);
|
||||
Thread.Sleep (50);
|
||||
Assert.AreEqual (1, b.count);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestNegativeDelay ()
|
||||
{
|
||||
Bucket b = new Bucket ();
|
||||
try {
|
||||
new Timer (new TimerCallback (Callback), b, -10,
|
||||
Timeout.Infinite);
|
||||
Assert.Fail ();
|
||||
} catch (ArgumentOutOfRangeException) {
|
||||
return;
|
||||
using (new Timer (o => Callback (o), b, 0, Int32.MaxValue)) {
|
||||
Thread.Sleep (50);
|
||||
Assert.AreEqual (1, b.count);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException (typeof (ArgumentOutOfRangeException))]
|
||||
public void TestNegativeDelay ()
|
||||
{
|
||||
Bucket b = new Bucket ();
|
||||
|
||||
using (new Timer (o => Callback (o), b, -10, Timeout.Infinite)) {
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException (typeof (ArgumentOutOfRangeException))]
|
||||
public void TestNegativePeriod ()
|
||||
{
|
||||
Bucket b = new Bucket ();
|
||||
try {
|
||||
new Timer (new TimerCallback (Callback), b, 0,
|
||||
-10);
|
||||
Assert.Fail ();
|
||||
} catch (ArgumentOutOfRangeException) {
|
||||
return;
|
||||
|
||||
using (new Timer (o => Callback (o), b, 0, -10)) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,11 +188,13 @@ namespace MonoTests.System.Threading {
|
||||
public void TestDelayZeroPeriodZero()
|
||||
{
|
||||
Bucket b = new Bucket();
|
||||
Timer t = new Timer(new TimerCallback(Callback),b,0,0);
|
||||
Thread.Sleep(100);
|
||||
t.Change (int.MaxValue, Timeout.Infinite);
|
||||
// since period is 0 the callback should happen once (bug #340212)
|
||||
Assert.AreEqual (1, b.count, "only once");
|
||||
|
||||
using (Timer t = new Timer(o => Callback (o),b,0,0)) {
|
||||
Thread.Sleep(100);
|
||||
t.Change (int.MaxValue, Timeout.Infinite);
|
||||
// since period is 0 the callback should happen once (bug #340212)
|
||||
Assert.AreEqual (1, b.count, "only once");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -204,7 +205,7 @@ namespace MonoTests.System.Threading {
|
||||
// that was ignored before 238785a3e3d510528228fc551625975bc508c2f3 and most unit test runner won't
|
||||
// report it since the NRE will not happen on the main thread (but Touch.Unit will)
|
||||
Timer t1 = null;
|
||||
t1 = new Timer (new TimerCallback (CallbackTestDisposeOnCallback), t1, 0, 10);
|
||||
t1 = new Timer (o => CallbackTestDisposeOnCallback (o), t1, 0, 10);
|
||||
Thread.Sleep (200);
|
||||
Assert.IsNotNull (t1);
|
||||
|
||||
@@ -225,7 +226,7 @@ namespace MonoTests.System.Threading {
|
||||
[ExpectedException (typeof (ArgumentNullException))]
|
||||
public void DisposeNullWaitHandle ()
|
||||
{
|
||||
using (Timer t = new Timer (DoNothing, null, 0, 0)) {
|
||||
using (Timer t = new Timer (o => DoNothing (o), null, 0, 0)) {
|
||||
t.Dispose (null);
|
||||
}
|
||||
}
|
||||
@@ -233,7 +234,7 @@ namespace MonoTests.System.Threading {
|
||||
[Test]
|
||||
public void Change_IntInt_Infinite ()
|
||||
{
|
||||
using (Timer t = new Timer (DoNothing, null, 0, 0)) {
|
||||
using (Timer t = new Timer (o => DoNothing (o), null, 0, 0)) {
|
||||
t.Change ((int)Timeout.Infinite, (int)Timeout.Infinite);
|
||||
}
|
||||
}
|
||||
@@ -241,7 +242,7 @@ namespace MonoTests.System.Threading {
|
||||
[Test]
|
||||
public void Change_IntInt_MaxValue ()
|
||||
{
|
||||
using (Timer t = new Timer (DoNothing, null, 0, 0)) {
|
||||
using (Timer t = new Timer (o => DoNothing (o), null, 0, 0)) {
|
||||
t.Change (Int32.MaxValue, Int32.MaxValue);
|
||||
}
|
||||
}
|
||||
@@ -249,7 +250,7 @@ namespace MonoTests.System.Threading {
|
||||
[Test]
|
||||
public void Change_UIntUInt_Infinite ()
|
||||
{
|
||||
using (Timer t = new Timer (DoNothing, null, 0, 0)) {
|
||||
using (Timer t = new Timer (o => DoNothing (o), null, 0, 0)) {
|
||||
t.Change (unchecked ((uint) Timeout.Infinite), unchecked ((uint) Timeout.Infinite));
|
||||
}
|
||||
}
|
||||
@@ -257,7 +258,7 @@ namespace MonoTests.System.Threading {
|
||||
[Test]
|
||||
public void Change_UIntUInt_MaxValue ()
|
||||
{
|
||||
using (Timer t = new Timer (DoNothing, null, 0, 0)) {
|
||||
using (Timer t = new Timer (o => DoNothing (o), null, 0, 0)) {
|
||||
// UInt32.MaxValue == Timeout.Infinite == 0xffffffff
|
||||
t.Change (UInt32.MaxValue, UInt32.MaxValue);
|
||||
}
|
||||
@@ -266,7 +267,7 @@ namespace MonoTests.System.Threading {
|
||||
[Test]
|
||||
public void Change_LongLong_Infinite ()
|
||||
{
|
||||
using (Timer t = new Timer (DoNothing, null, 0, 0)) {
|
||||
using (Timer t = new Timer (o => DoNothing (o), null, 0, 0)) {
|
||||
t.Change ((long) Timeout.Infinite, (long) Timeout.Infinite);
|
||||
}
|
||||
}
|
||||
@@ -275,7 +276,7 @@ namespace MonoTests.System.Threading {
|
||||
[ExpectedException (typeof (ArgumentOutOfRangeException))]
|
||||
public void Change_LongLong_MaxValue ()
|
||||
{
|
||||
using (Timer t = new Timer (DoNothing, null, 0, 0)) {
|
||||
using (Timer t = new Timer (o => DoNothing (o), null, 0, 0)) {
|
||||
t.Change (Int64.MaxValue, Int64.MaxValue);
|
||||
}
|
||||
}
|
||||
@@ -284,7 +285,7 @@ namespace MonoTests.System.Threading {
|
||||
[ExpectedException (typeof (ArgumentOutOfRangeException))]
|
||||
public void Change_LongLong_UInt32MaxValue ()
|
||||
{
|
||||
using (Timer t = new Timer (DoNothing, null, 0, 0)) {
|
||||
using (Timer t = new Timer (o => DoNothing (o), null, 0, 0)) {
|
||||
// not identical to (long)-1
|
||||
t.Change ((long)UInt32.MaxValue, (long)UInt32.MaxValue);
|
||||
}
|
||||
@@ -293,7 +294,7 @@ namespace MonoTests.System.Threading {
|
||||
[Test]
|
||||
public void Change_LongLong_UInt32MaxValueMinusOne ()
|
||||
{
|
||||
using (Timer t = new Timer (DoNothing, null, 0, 0)) {
|
||||
using (Timer t = new Timer (o => DoNothing (o), null, 0, 0)) {
|
||||
// not identical to (long)-1
|
||||
t.Change ((long) UInt32.MaxValue - 1, (long) UInt32.MaxValue -1);
|
||||
}
|
||||
@@ -302,7 +303,7 @@ namespace MonoTests.System.Threading {
|
||||
[Test]
|
||||
public void Change_TimeSpanTimeSpan_Infinite ()
|
||||
{
|
||||
using (Timer t = new Timer (DoNothing, null, 0, 0)) {
|
||||
using (Timer t = new Timer (o => DoNothing (o), null, 0, 0)) {
|
||||
t.Change (new TimeSpan (-1), new TimeSpan (-1));
|
||||
}
|
||||
}
|
||||
@@ -311,7 +312,7 @@ namespace MonoTests.System.Threading {
|
||||
[ExpectedException (typeof (ArgumentOutOfRangeException))]
|
||||
public void Change_TimeSpanTimeSpan_MaxValue ()
|
||||
{
|
||||
using (Timer t = new Timer (DoNothing, null, 0, 0)) {
|
||||
using (Timer t = new Timer (o => DoNothing (o), null, 0, 0)) {
|
||||
t.Change (TimeSpan.MaxValue, TimeSpan.MaxValue);
|
||||
}
|
||||
}
|
||||
@@ -319,7 +320,7 @@ namespace MonoTests.System.Threading {
|
||||
[Test]
|
||||
public void Change_TimeSpanTimeSpan_UInt32MaxValue ()
|
||||
{
|
||||
using (Timer t = new Timer (DoNothing, null, 0, 0)) {
|
||||
using (Timer t = new Timer (o => DoNothing (o), null, 0, 0)) {
|
||||
t.Change (new TimeSpan (UInt32.MaxValue), new TimeSpan (UInt32.MaxValue));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user