Skip to content

Commit 0513eaf

Browse files
Extract a helper
1 parent 8378b8a commit 0513eaf

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class TestConcurrentAccessWithSharedConnection : IntegrationFixture {
5353

5454
protected const int threads = 32;
5555
protected CountdownEvent latch;
56+
protected TimeSpan completionTimeout = TimeSpan.FromSeconds(90);
5657

5758
[SetUp]
5859
public void Init()
@@ -94,21 +95,39 @@ public void TestConcurrentChannelOpenWithPublishing()
9495
// to segfault on OS X for no obvious reason
9596
[Test]
9697
public void TestConcurrentChannelOpenCloseLoop()
98+
{
99+
TestConcurrentChannelOperations((conn) => {
100+
var ch = conn.CreateModel();
101+
ch.Close();
102+
}, 100);
103+
}
104+
105+
protected void TestConcurrentChannelOperations(Action<IConnection> actions,
106+
int iterations)
107+
{
108+
TestConcurrentChannelOperations(actions, iterations, completionTimeout);
109+
}
110+
111+
protected void TestConcurrentChannelOperations(Action<IConnection> actions,
112+
int iterations, TimeSpan timeout)
97113
{
98114
foreach (var i in Enumerable.Range(0, threads))
99115
{
100116
var t = new Thread(() => {
101-
foreach (var j in Enumerable.Range(0, 100))
117+
foreach (var j in Enumerable.Range(0, iterations))
102118
{
103-
var ch = Conn.CreateModel();
104-
ch.Close();
119+
actions(Conn);
105120
}
106121
latch.Signal();
107122
});
108123
t.Start();
109124
}
110125

111-
Assert.IsTrue(latch.Wait(TimeSpan.FromSeconds(90)));
126+
Assert.IsTrue(latch.Wait(timeout));
127+
// incorrect frame interleaving in these tests will result
128+
// in an unrecoverable connection-level exception, thus
129+
// closing the connection
130+
Assert.IsTrue(Conn.IsOpen);
112131
}
113132
}
114133
}

0 commit comments

Comments
 (0)