Skip to content

Commit f85296e

Browse files
committed
Revert to old WaitForConfirmsOrDieAsync behavior (reverts part of #999). Fix test
1 parent a262b61 commit f85296e

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

projects/RabbitMQ.Client/client/impl/ChannelBase.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,13 +1652,16 @@ await CloseAsync(
16521652
new IOException("nack received")),
16531653
false).ConfigureAwait(false);
16541654
}
1655-
catch (TaskCanceledException exception)
1655+
catch (TaskCanceledException)
16561656
{
1657+
const string msg = "timed out waiting for acks";
1658+
var ex = new IOException(msg);
16571659
await CloseAsync(new ShutdownEventArgs(ShutdownInitiator.Library,
16581660
Constants.ReplySuccess,
1659-
"Timed out waiting for acks",
1660-
exception),
1661+
msg,
1662+
ex),
16611663
false).ConfigureAwait(false);
1664+
throw ex;
16621665
}
16631666
}
16641667

projects/Test/Integration/TestPublisherConfirms.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ namespace Test.Integration
4444
{
4545
public class TestPublisherConfirms : IntegrationFixture
4646
{
47-
private const string QueueName = "Test.Integration.TestPublisherConfirms";
4847
private readonly byte[] _body = new byte[4096];
4948

5049
public TestPublisherConfirms(ITestOutputHelper output) : base(output)
@@ -79,10 +78,10 @@ public Task TestWaitForConfirmsWithTimeout()
7978
}
8079

8180
[Fact]
82-
public Task TestWaitForConfirmsWithTimeoutAsync_MightThrowTaskCanceledException()
81+
public async Task TestWaitForConfirmsWithTimeoutAsync_MightThrowTaskCanceledException()
8382
{
8483
bool waitResult = false;
85-
bool sawTaskCanceled = false;
84+
bool sawException = false;
8685

8786
Task t = TestWaitForConfirmsAsync(10000, async (ch) =>
8887
{
@@ -92,19 +91,19 @@ public Task TestWaitForConfirmsWithTimeoutAsync_MightThrowTaskCanceledException(
9291
{
9392
waitResult = await ch.WaitForConfirmsAsync(cts.Token);
9493
}
95-
catch (TaskCanceledException)
94+
catch
9695
{
97-
sawTaskCanceled = true;
96+
sawException = true;
9897
}
9998
}
10099
});
101100

102-
if (waitResult == false && sawTaskCanceled == false)
101+
await t;
102+
103+
if (waitResult == false && sawException == false)
103104
{
104-
Assert.Fail("test failed, both waitResult and sawTaskCanceled are still false");
105+
Assert.Fail("test failed, both waitResult and sawException are still false");
105106
}
106-
107-
return t;
108107
}
109108

110109
[Fact]
@@ -128,10 +127,11 @@ public Task TestWaitForConfirmsWithTimeoutAsync_MessageNacked_WaitingHasTimedout
128127
[Fact]
129128
public async Task TestWaitForConfirmsWithEventsAsync()
130129
{
130+
string queueName = string.Format("{0}:{1}", _testDisplayName, Guid.NewGuid());
131131
using (IChannel ch = _conn.CreateChannel())
132132
{
133133
await ch.ConfirmSelectAsync();
134-
await ch.QueueDeclareAsync(queue: QueueName, passive: false, durable: false, exclusive: false, autoDelete: false, arguments: null);
134+
await ch.QueueDeclareAsync(queue: queueName, passive: false, durable: false, exclusive: false, autoDelete: false, arguments: null);
135135

136136
int n = 200;
137137
// number of event handler invocations
@@ -146,7 +146,7 @@ public async Task TestWaitForConfirmsWithEventsAsync()
146146
{
147147
for (int i = 0; i < n; i++)
148148
{
149-
await ch.BasicPublishAsync("", QueueName, _encoding.GetBytes("msg"));
149+
await ch.BasicPublishAsync("", queueName, _encoding.GetBytes("msg"));
150150
}
151151

152152
await ch.WaitForConfirmsAsync();
@@ -159,23 +159,24 @@ public async Task TestWaitForConfirmsWithEventsAsync()
159159
}
160160
finally
161161
{
162-
await ch.QueueDeleteAsync(queue: QueueName, ifUnused: false, ifEmpty: false);
162+
await ch.QueueDeleteAsync(queue: queueName, ifUnused: false, ifEmpty: false);
163163
}
164164
}
165165
}
166166

167167
private async Task TestWaitForConfirmsAsync(int numberOfMessagesToPublish, Func<IChannel, Task> fn)
168168
{
169+
string queueName = string.Format("{0}:{1}", _testDisplayName, Guid.NewGuid());
169170
using (IChannel ch = _conn.CreateChannel())
170171
{
171172
var props = new BasicProperties { Persistent = true };
172173

173174
await ch.ConfirmSelectAsync();
174-
await ch.QueueDeclareAsync(queue: QueueName, passive: false, durable: false, exclusive: false, autoDelete: false, arguments: null);
175+
await ch.QueueDeclareAsync(queue: queueName, passive: false, durable: false, exclusive: false, autoDelete: false, arguments: null);
175176

176177
for (int i = 0; i < numberOfMessagesToPublish; i++)
177178
{
178-
await ch.BasicPublishAsync(exchange: "", routingKey: QueueName, body: _body, mandatory: true, basicProperties: props);
179+
await ch.BasicPublishAsync(exchange: string.Empty, routingKey: queueName, body: _body, mandatory: true, basicProperties: props);
179180
}
180181

181182
try
@@ -184,7 +185,7 @@ private async Task TestWaitForConfirmsAsync(int numberOfMessagesToPublish, Func<
184185
}
185186
finally
186187
{
187-
await ch.QueueDeleteAsync(queue: QueueName, ifUnused: false, ifEmpty: false);
188+
await ch.QueueDeleteAsync(queue: queueName, ifUnused: false, ifEmpty: false);
188189
}
189190
}
190191
}

0 commit comments

Comments
 (0)