Skip to content

Commit 6b172e6

Browse files
Add random sleep intervals to increase chances of thread interleaving
We don't have much control over VM scheduler, so will have to do this.
1 parent 811cd38 commit 6b172e6

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

projects/client/Unit/src/unit/TestExchangeDeclare.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class TestExchangeDeclare : IntegrationFixture {
5454
public void TestConcurrentQueueDeclare()
5555
{
5656
string x = GenerateExchangeName();
57+
Random rnd = new Random();
5758

5859
List<Thread> ts = new List<Thread>();
5960
System.NotSupportedException nse = null;
@@ -63,6 +64,9 @@ public void TestConcurrentQueueDeclare()
6364
{
6465
try
6566
{
67+
// sleep for a random amount of time to increase the chances
68+
// of thread interleaving. MK.
69+
Thread.Sleep(rnd.Next(5, 500));
6670
Model.ExchangeDeclare(x, "fanout", false, false, null);
6771
} catch (System.NotSupportedException e)
6872
{

projects/client/Unit/src/unit/TestQueueDeclare.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class TestQueueDeclare : IntegrationFixture {
5454
public void TestConcurrentQueueDeclare()
5555
{
5656
string q = GenerateQueueName();
57+
Random rnd = new Random();
5758

5859
List<Thread> ts = new List<Thread>();
5960
System.NotSupportedException nse = null;
@@ -63,6 +64,9 @@ public void TestConcurrentQueueDeclare()
6364
{
6465
try
6566
{
67+
// sleep for a random amount of time to increase the chances
68+
// of thread interleaving. MK.
69+
Thread.Sleep(rnd.Next(5, 500));
6670
Model.QueueDeclare(q, false, false, false, null);
6771
} catch (System.NotSupportedException e)
6872
{

0 commit comments

Comments
 (0)