New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disable some flaky tests and harden another one. #4376
Changes from 1 commit
cd7a379
769d2a6
779b5e8
aaf7b00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ public class TimerTest { | |
// this bucket is used to avoid non-theadlocal issues | ||
class Bucket { | ||
public int count; | ||
public ManualResetEventSlim mre = new ManualResetEventSlim (false); | ||
} | ||
|
||
[SetUp] | ||
|
@@ -36,74 +37,70 @@ void DoNothing (object foo) | |
{ | ||
} | ||
|
||
private void Callback2 (object foo) | ||
{ | ||
Bucket b = foo as Bucket; | ||
Interlocked.Increment (ref b.count); | ||
b.mre.Set (); | ||
} | ||
|
||
|
||
[Test] | ||
[Category ("NotWorking")] | ||
public void TestDueTime () | ||
{ | ||
Bucket bucket = new Bucket(); | ||
|
||
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"); | ||
using (Timer t = new Timer (o => Callback2 (o), bucket, 200, Timeout.Infinite)) { | ||
bucket.mre.Wait (5000); | ||
Assert.AreEqual (1, bucket.count, "#1"); | ||
} | ||
} | ||
|
||
[Test] | ||
[Category ("NotWorking")] | ||
public void TestDispose () | ||
{ | ||
Bucket bucket = new Bucket(); | ||
|
||
using (Timer t = new Timer (o => Callback2 (o), bucket, 10, 10)) { | ||
bucket.mre.Wait (5000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should do Assert.True (...) |
||
} | ||
//If the callback is called after dispose, it will NRE and be reported | ||
bucket.mre = null; | ||
int c = bucket.count; | ||
Assert.IsTrue (c > 0, "#1"); | ||
} | ||
|
||
[Test] | ||
public void TestChange () | ||
{ | ||
Bucket bucket = new Bucket(); | ||
|
||
using (Timer t = new Timer (o => Callback (o), bucket, 10, 10)) { | ||
Thread.Sleep (500); | ||
using (Timer t = new Timer (o => Callback2 (o), bucket, 10, 10)) { | ||
bucket.mre.Wait (5000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should do Assert.True (...) |
||
int c = bucket.count; | ||
Assert.IsTrue (c > 20, "#1 " + c.ToString ()); | ||
t.Change (100, 100); | ||
Assert.IsTrue (c > 0, "#1 " + c); | ||
t.Change (100000, 1000000); | ||
c = bucket.count; | ||
Thread.Sleep (500); | ||
Assert.IsTrue (bucket.count <= c + 20, "#2 " + c.ToString ()); | ||
Assert.IsTrue (bucket.count <= c + 1, "#2 " + c); | ||
} | ||
} | ||
|
||
[Test] | ||
[Category ("NotWorking")] | ||
public void TestZeroDueTime () | ||
{ | ||
Bucket bucket = new Bucket(); | ||
|
||
using (Timer t = new Timer (o => Callback (o), bucket, 0, Timeout.Infinite)) { | ||
Thread.Sleep (100); | ||
using (Timer t = new Timer (o => Callback2 (o), bucket, 0, Timeout.Infinite)) { | ||
bucket.mre.Wait (5000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should do Assert.True (...) |
||
bucket.mre.Reset (); | ||
Assert.AreEqual (1, bucket.count, "#1"); | ||
t.Change (0, Timeout.Infinite); | ||
Thread.Sleep (100); | ||
bucket.mre.Wait (5000); | ||
Assert.AreEqual (2, bucket.count, "#2"); | ||
} | ||
} | ||
|
||
[Test] | ||
[Category ("NotWorking")] | ||
public void TestDispose () | ||
{ | ||
Bucket bucket = new Bucket(); | ||
|
||
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"); | ||
Thread.Sleep (200); | ||
Assert.AreEqual (c, bucket.count, "#2"); | ||
} | ||
|
||
[Test] // bug #320950 | ||
public void TestDispose2 () | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should do Assert.True (...)