Skip to content

Commit 360a604

Browse files
Make heartbeat tests run longer and conditionally
1 parent 8e4e87b commit 360a604

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ internal class TestHeartbeats : IntegrationFixture
5555
[Category("Focus")]
5656
public void TestThatHeartbeatWriterUsesConfigurableInterval()
5757
{
58+
if (!LongRunningTestsEnabled())
59+
{
60+
Console.WriteLine("RABBITMQ_LONG_RUNNING_TESTS is not set, skipping test");
61+
return;
62+
}
63+
5864
var cf = new ConnectionFactory()
5965
{
6066
RequestedHeartbeat = heartbeatTimeout,
@@ -75,7 +81,7 @@ public void TestThatHeartbeatWriterUsesConfigurableInterval()
7581
}
7682
}
7783
};
78-
Thread.Sleep(heartbeatTimeout * 10 * 1000);
84+
SleepFor(30);
7985

8086
Assert.IsFalse(wasShutdown, "shutdown event should not have been fired");
8187
Assert.IsTrue(conn.IsOpen, "connection should be open");
@@ -87,6 +93,13 @@ public void TestThatHeartbeatWriterUsesConfigurableInterval()
8793
[Category("Focus")]
8894
public void TestHundredsOfConnectionsWithRandomHeartbeatInterval()
8995
{
96+
if (!LongRunningTestsEnabled())
97+
{
98+
Console.WriteLine("RABBITMQ_LONG_RUNNING_TESTS is not set, skipping test");
99+
return;
100+
}
101+
102+
90103
var rnd = new Random();
91104
List<IConnection> xs = new List<IConnection>();
92105
for(var i = 0; i < 200; i++)
@@ -104,7 +117,7 @@ public void TestHundredsOfConnectionsWithRandomHeartbeatInterval()
104117
};
105118
}
106119

107-
Thread.Sleep(20 * 1000);
120+
SleepFor(60);
108121

109122
foreach(var x in xs)
110123
{
@@ -123,5 +136,21 @@ private void CheckInitiator(ShutdownEventArgs evt)
123136
Assert.Fail(s);
124137
}
125138
}
139+
140+
private bool LongRunningTestsEnabled()
141+
{
142+
var s = Environment.GetEnvironmentVariable("RABBITMQ_LONG_RUNNING_TESTS");
143+
if(s == null || s.Equals(""))
144+
{
145+
return false;
146+
}
147+
return true;
148+
}
149+
150+
private void SleepFor(int t)
151+
{
152+
Console.WriteLine("Testing heartbeats, sleeping for {0} seconds", t);
153+
Thread.Sleep(t * 1000);
154+
}
126155
}
127156
}

0 commit comments

Comments
 (0)