Imported Upstream version 4.3.2.467

Former-commit-id: 9c2cb47f45fa221e661ab616387c9cda183f283d
This commit is contained in:
Xamarin Public Jenkins
2016-02-22 11:00:01 -05:00
parent f302175246
commit f3e3aab35a
4097 changed files with 122406 additions and 82300 deletions

View File

@ -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));
}
}