Skip to content

Commit 36e1531

Browse files
committed
* Move event handler recovery tests to their own classes to enable parallel execution.
1 parent ed77c12 commit 36e1531

File tree

5 files changed

+249
-68
lines changed

5 files changed

+249
-68
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// This source code is dual-licensed under the Apache License, version
2+
// 2.0, and the Mozilla Public License, version 2.0.
3+
//
4+
// The APL v2.0:
5+
//
6+
//---------------------------------------------------------------------------
7+
// Copyright (c) 2007-2020 VMware, Inc.
8+
//
9+
// Licensed under the Apache License, Version 2.0 (the "License");
10+
// you may not use this file except in compliance with the License.
11+
// You may obtain a copy of the License at
12+
//
13+
// https://www.apache.org/licenses/LICENSE-2.0
14+
//
15+
// Unless required by applicable law or agreed to in writing, software
16+
// distributed under the License is distributed on an "AS IS" BASIS,
17+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
// See the License for the specific language governing permissions and
19+
// limitations under the License.
20+
//---------------------------------------------------------------------------
21+
//
22+
// The MPL v2.0:
23+
//
24+
//---------------------------------------------------------------------------
25+
// This Source Code Form is subject to the terms of the Mozilla Public
26+
// License, v. 2.0. If a copy of the MPL was not distributed with this
27+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
28+
//
29+
// Copyright (c) 2007-2020 VMware, Inc. All rights reserved.
30+
//---------------------------------------------------------------------------
31+
32+
using System.Threading;
33+
using System.Threading.Tasks;
34+
using RabbitMQ.Client.Impl;
35+
using Xunit;
36+
using Xunit.Abstractions;
37+
38+
namespace Test.Integration.ConnectionRecovery.EventHandlerRecovery.Channel
39+
{
40+
public class TestRecoveryEventHandlers : TestConnectionRecoveryBase
41+
{
42+
public TestRecoveryEventHandlers(ITestOutputHelper output) : base(output)
43+
{
44+
}
45+
46+
[Fact]
47+
public async Task TestRecoveryEventHandlers_Called()
48+
{
49+
int counter = 0;
50+
((AutorecoveringChannel)_channel).Recovery += (source, ea) => Interlocked.Increment(ref counter);
51+
52+
await CloseAndWaitForRecoveryAsync();
53+
await CloseAndWaitForRecoveryAsync();
54+
await CloseAndWaitForRecoveryAsync();
55+
await CloseAndWaitForRecoveryAsync();
56+
Assert.True(_channel.IsOpen);
57+
Assert.True(counter >= 3);
58+
}
59+
}
60+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// This source code is dual-licensed under the Apache License, version
2+
// 2.0, and the Mozilla Public License, version 2.0.
3+
//
4+
// The APL v2.0:
5+
//
6+
//---------------------------------------------------------------------------
7+
// Copyright (c) 2007-2020 VMware, Inc.
8+
//
9+
// Licensed under the Apache License, Version 2.0 (the "License");
10+
// you may not use this file except in compliance with the License.
11+
// You may obtain a copy of the License at
12+
//
13+
// https://www.apache.org/licenses/LICENSE-2.0
14+
//
15+
// Unless required by applicable law or agreed to in writing, software
16+
// distributed under the License is distributed on an "AS IS" BASIS,
17+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
// See the License for the specific language governing permissions and
19+
// limitations under the License.
20+
//---------------------------------------------------------------------------
21+
//
22+
// The MPL v2.0:
23+
//
24+
//---------------------------------------------------------------------------
25+
// This Source Code Form is subject to the terms of the Mozilla Public
26+
// License, v. 2.0. If a copy of the MPL was not distributed with this
27+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
28+
//
29+
// Copyright (c) 2007-2020 VMware, Inc. All rights reserved.
30+
//---------------------------------------------------------------------------
31+
32+
using System.Threading;
33+
using System.Threading.Tasks;
34+
using Xunit;
35+
using Xunit.Abstractions;
36+
37+
namespace Test.Integration.ConnectionRecovery.EventHandlerRecovery.Channel
38+
{
39+
public class TestShutdownEventHandlers : TestConnectionRecoveryBase
40+
{
41+
public TestShutdownEventHandlers(ITestOutputHelper output) : base(output)
42+
{
43+
}
44+
45+
[Fact]
46+
public async Task TestShutdownEventHandlersOnChannel_Called()
47+
{
48+
int counter = 0;
49+
_channel.ChannelShutdown += (c, args) => Interlocked.Increment(ref counter);
50+
51+
Assert.True(_channel.IsOpen);
52+
await CloseAndWaitForRecoveryAsync();
53+
await CloseAndWaitForRecoveryAsync();
54+
await CloseAndWaitForRecoveryAsync();
55+
await CloseAndWaitForRecoveryAsync();
56+
Assert.True(_channel.IsOpen);
57+
58+
Assert.True(counter >= 3);
59+
}
60+
}
61+
}

projects/Test/Integration/ConnectionRecovery/TestEventHandlerRecovery.cs renamed to projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestRecoveringConsumerEventHandlers.cs

Lines changed: 7 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -35,52 +35,23 @@
3535
using RabbitMQ.Client;
3636
using RabbitMQ.Client.Events;
3737
using RabbitMQ.Client.Framing.Impl;
38-
using RabbitMQ.Client.Impl;
3938
using Xunit;
4039
using Xunit.Abstractions;
4140

42-
namespace Test.Integration.ConnectionRecovery
41+
namespace Test.Integration.ConnectionRecovery.EventHandlerRecovery.Connection
4342
{
44-
public class TestEventHandlerRecovery : TestConnectionRecoveryBase
43+
public class TestRecoveringConsumerEventHandlers : TestConnectionRecoveryBase
4544
{
46-
public TestEventHandlerRecovery(ITestOutputHelper output) : base(output)
45+
public TestRecoveringConsumerEventHandlers(ITestOutputHelper output) : base(output)
4746
{
4847
}
4948

50-
[Fact]
51-
public async Task TestRecoveryEventHandlersOnConnection()
52-
{
53-
int counter = 0;
54-
((AutorecoveringConnection)_conn).RecoverySucceeded += (source, ea) => Interlocked.Increment(ref counter);
55-
56-
await CloseAndWaitForRecoveryAsync();
57-
await CloseAndWaitForRecoveryAsync();
58-
await CloseAndWaitForRecoveryAsync();
59-
await CloseAndWaitForRecoveryAsync();
60-
Assert.True(_conn.IsOpen);
61-
Assert.True(counter >= 3);
62-
}
63-
64-
[Fact]
65-
public async Task TestRecoveryEventHandlersOnChannel()
66-
{
67-
int counter = 0;
68-
((AutorecoveringChannel)_channel).Recovery += (source, ea) => Interlocked.Increment(ref counter);
69-
70-
await CloseAndWaitForRecoveryAsync();
71-
await CloseAndWaitForRecoveryAsync();
72-
await CloseAndWaitForRecoveryAsync();
73-
await CloseAndWaitForRecoveryAsync();
74-
Assert.True(_channel.IsOpen);
75-
Assert.True(counter >= 3);
76-
}
77-
7849
[Theory]
7950
[InlineData(1)]
8051
[InlineData(3)]
81-
public async Task TestRecoveringConsumerHandlerOnConnection(int iterations)
52+
public async Task TestRecoveringConsumerEventHandlers_Called(int iterations)
8253
{
83-
string q = (await _channel.QueueDeclareAsync(GenerateQueueName(), false, false, false)).QueueName;
54+
RabbitMQ.Client.QueueDeclareOk q = await _channel.QueueDeclareAsync(GenerateQueueName(), false, false, false);
8455
var cons = new EventingBasicConsumer(_channel);
8556
await _channel.BasicConsumeAsync(q, true, cons);
8657

@@ -96,10 +67,10 @@ public async Task TestRecoveringConsumerHandlerOnConnection(int iterations)
9667
}
9768

9869
[Fact]
99-
public async Task TestRecoveringConsumerHandlerOnConnection_EventArgumentsArePassedDown()
70+
public async Task TestRecoveringConsumerEventHandler_EventArgumentsArePassedDown()
10071
{
10172
var myArgs = new Dictionary<string, object> { { "first-argument", "some-value" } };
102-
string q = (await _channel.QueueDeclareAsync(GenerateQueueName(), false, false, false)).QueueName;
73+
RabbitMQ.Client.QueueDeclareOk q = await _channel.QueueDeclareAsync(GenerateQueueName(), false, false, false);
10374
var cons = new EventingBasicConsumer(_channel);
10475
string expectedCTag = await _channel.BasicConsumeAsync(cons, q, arguments: myArgs);
10576

@@ -121,37 +92,5 @@ public async Task TestRecoveringConsumerHandlerOnConnection_EventArgumentsArePas
12192
string actualVal = (string)Assert.Contains("first-argument", myArgs as IDictionary<string, object>);
12293
Assert.Equal("event-handler-set-this-value", actualVal);
12394
}
124-
125-
[Fact]
126-
public async Task TestShutdownEventHandlersRecoveryOnConnection()
127-
{
128-
int counter = 0;
129-
_conn.ConnectionShutdown += (c, args) => Interlocked.Increment(ref counter);
130-
131-
Assert.True(_conn.IsOpen);
132-
await CloseAndWaitForRecoveryAsync();
133-
await CloseAndWaitForRecoveryAsync();
134-
await CloseAndWaitForRecoveryAsync();
135-
await CloseAndWaitForRecoveryAsync();
136-
Assert.True(_conn.IsOpen);
137-
138-
Assert.True(counter >= 3);
139-
}
140-
141-
[Fact]
142-
public async Task TestShutdownEventHandlersRecoveryOnChannel()
143-
{
144-
int counter = 0;
145-
_channel.ChannelShutdown += (c, args) => Interlocked.Increment(ref counter);
146-
147-
Assert.True(_channel.IsOpen);
148-
await CloseAndWaitForRecoveryAsync();
149-
await CloseAndWaitForRecoveryAsync();
150-
await CloseAndWaitForRecoveryAsync();
151-
await CloseAndWaitForRecoveryAsync();
152-
Assert.True(_channel.IsOpen);
153-
154-
Assert.True(counter >= 3);
155-
}
15695
}
15796
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// This source code is dual-licensed under the Apache License, version
2+
// 2.0, and the Mozilla Public License, version 2.0.
3+
//
4+
// The APL v2.0:
5+
//
6+
//---------------------------------------------------------------------------
7+
// Copyright (c) 2007-2020 VMware, Inc.
8+
//
9+
// Licensed under the Apache License, Version 2.0 (the "License");
10+
// you may not use this file except in compliance with the License.
11+
// You may obtain a copy of the License at
12+
//
13+
// https://www.apache.org/licenses/LICENSE-2.0
14+
//
15+
// Unless required by applicable law or agreed to in writing, software
16+
// distributed under the License is distributed on an "AS IS" BASIS,
17+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
// See the License for the specific language governing permissions and
19+
// limitations under the License.
20+
//---------------------------------------------------------------------------
21+
//
22+
// The MPL v2.0:
23+
//
24+
//---------------------------------------------------------------------------
25+
// This Source Code Form is subject to the terms of the Mozilla Public
26+
// License, v. 2.0. If a copy of the MPL was not distributed with this
27+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
28+
//
29+
// Copyright (c) 2007-2020 VMware, Inc. All rights reserved.
30+
//---------------------------------------------------------------------------
31+
32+
using System.Threading;
33+
using System.Threading.Tasks;
34+
using RabbitMQ.Client.Framing.Impl;
35+
using Xunit;
36+
using Xunit.Abstractions;
37+
38+
namespace Test.Integration.ConnectionRecovery.EventHandlerRecovery.Connection
39+
{
40+
public class TestRecoverySucceededEventHandlers : TestConnectionRecoveryBase
41+
{
42+
public TestRecoverySucceededEventHandlers(ITestOutputHelper output) : base(output)
43+
{
44+
}
45+
46+
[Fact]
47+
public async Task TestRecoverySucceededEventHandlers_Called()
48+
{
49+
int counter = 0;
50+
((AutorecoveringConnection)_conn).RecoverySucceeded += (source, ea) => Interlocked.Increment(ref counter);
51+
52+
await CloseAndWaitForRecoveryAsync();
53+
await CloseAndWaitForRecoveryAsync();
54+
await CloseAndWaitForRecoveryAsync();
55+
await CloseAndWaitForRecoveryAsync();
56+
Assert.True(_conn.IsOpen);
57+
Assert.True(counter >= 3);
58+
}
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// This source code is dual-licensed under the Apache License, version
2+
// 2.0, and the Mozilla Public License, version 2.0.
3+
//
4+
// The APL v2.0:
5+
//
6+
//---------------------------------------------------------------------------
7+
// Copyright (c) 2007-2020 VMware, Inc.
8+
//
9+
// Licensed under the Apache License, Version 2.0 (the "License");
10+
// you may not use this file except in compliance with the License.
11+
// You may obtain a copy of the License at
12+
//
13+
// https://www.apache.org/licenses/LICENSE-2.0
14+
//
15+
// Unless required by applicable law or agreed to in writing, software
16+
// distributed under the License is distributed on an "AS IS" BASIS,
17+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
// See the License for the specific language governing permissions and
19+
// limitations under the License.
20+
//---------------------------------------------------------------------------
21+
//
22+
// The MPL v2.0:
23+
//
24+
//---------------------------------------------------------------------------
25+
// This Source Code Form is subject to the terms of the Mozilla Public
26+
// License, v. 2.0. If a copy of the MPL was not distributed with this
27+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
28+
//
29+
// Copyright (c) 2007-2020 VMware, Inc. All rights reserved.
30+
//---------------------------------------------------------------------------
31+
32+
using System.Threading;
33+
using System.Threading.Tasks;
34+
using Xunit;
35+
using Xunit.Abstractions;
36+
37+
namespace Test.Integration.ConnectionRecovery.EventHandlerRecovery.Connection
38+
{
39+
public class TestShutdownEventHandlers : TestConnectionRecoveryBase
40+
{
41+
public TestShutdownEventHandlers(ITestOutputHelper output) : base(output)
42+
{
43+
}
44+
45+
[Fact]
46+
public async Task TestShutdownEventHandlers_Called()
47+
{
48+
int counter = 0;
49+
_conn.ConnectionShutdown += (c, args) => Interlocked.Increment(ref counter);
50+
51+
Assert.True(_conn.IsOpen);
52+
await CloseAndWaitForRecoveryAsync();
53+
await CloseAndWaitForRecoveryAsync();
54+
await CloseAndWaitForRecoveryAsync();
55+
await CloseAndWaitForRecoveryAsync();
56+
Assert.True(_conn.IsOpen);
57+
58+
Assert.True(counter >= 3);
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)