Skip to content

Commit 9c938a0

Browse files
authored
Better exception message when a continuation times out (#1552)
1 parent 5325127 commit 9c938a0

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public AsyncRpcContinuation(TimeSpan continuationTimeout, CancellationToken canc
6868
{
6969
// Cancellation was successful, does this mean we set a TimeoutException
7070
// in the same manner as BlockingCell used to
71-
tcs.SetException(new TimeoutException("TODO LRB rabbitmq/rabbitmq-dotnet-client#1347"));
71+
string msg = $"operation '{GetType().FullName}' timed out after {continuationTimeout}";
72+
tcs.TrySetException(new TimeoutException(msg));
7273
}
7374
}, _tcs);
7475
#else
@@ -79,7 +80,8 @@ public AsyncRpcContinuation(TimeSpan continuationTimeout, CancellationToken canc
7980
{
8081
// Cancellation was successful, does this mean we set a TimeoutException
8182
// in the same manner as BlockingCell used to
82-
tcs.SetException(new TimeoutException("TODO LRB rabbitmq/rabbitmq-dotnet-client#1347"));
83+
string msg = $"operation '{GetType().FullName}' timed out after {continuationTimeout}";
84+
tcs.TrySetException(new TimeoutException(msg));
8385
}
8486
}, state: _tcs, useSynchronizationContext: false);
8587
#endif
@@ -109,7 +111,7 @@ public ConfiguredTaskAwaitable<T>.ConfiguredTaskAwaiter GetAwaiter()
109111

110112
public virtual void HandleChannelShutdown(ShutdownEventArgs reason)
111113
{
112-
_tcs.SetException(new OperationInterruptedException(reason));
114+
_tcs.TrySetException(new OperationInterruptedException(reason));
113115
}
114116

115117
protected virtual void Dispose(bool disposing)

projects/Test/Common/IntegrationFixture.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
using System.Linq;
3636
using System.Net.Sockets;
3737
using System.Reflection;
38+
using System.Runtime.CompilerServices;
3839
using System.Text;
3940
using System.Threading;
4041
using System.Threading.Tasks;
@@ -619,7 +620,7 @@ protected static string GetUniqueString(ushort length)
619620

620621
protected static byte[] GetRandomBody(ushort size = 1024)
621622
{
622-
var body = new byte[size];
623+
byte[] body = new byte[size];
623624
S_Random.NextBytes(body);
624625
return body;
625626
}
@@ -639,5 +640,15 @@ protected static TaskCompletionSource<bool> PrepareForRecovery(IConnection conn)
639640

640641
return tcs;
641642
}
643+
644+
protected void LogWarning(string text,
645+
[CallerFilePath] string file = "",
646+
[CallerMemberName] string member = "",
647+
[CallerLineNumber] int line = 0)
648+
{
649+
// https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-a-warning-message
650+
_output.WriteLine("::warning file={0},line={1}::{2} {3}",
651+
Path.GetFileName(file), line, member, text);
652+
}
642653
}
643654
}

projects/Test/Integration/ConnectionRecovery/TestRpcAfterRecovery.cs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
//---------------------------------------------------------------------------
3131

3232
using System;
33-
using System.IO;
34-
using System.Runtime.CompilerServices;
3533
using System.Threading.Tasks;
3634
using RabbitMQ.Client;
3735
using RabbitMQ.Client.Events;
@@ -97,7 +95,7 @@ public async Task TestPublishRpcRightAfterReconnect()
9795
*/
9896
if (a.ShutdownReason.ReplyCode == 406)
9997
{
100-
LogWarning(_output, "FIXME saw code 406");
98+
LogWarning("FIXME saw code 406");
10199
}
102100
}
103101
}
@@ -106,22 +104,12 @@ public async Task TestPublishRpcRightAfterReconnect()
106104

107105
if (now - start > WaitSpan)
108106
{
109-
LogWarning(_output, $"FIXME test exceeded wait time of {WaitSpan}");
107+
LogWarning($"FIXME test exceeded wait time of {WaitSpan}");
110108
}
111109

112110
} while (false == doneTcs.Task.IsCompletedSuccessfully());
113111

114112
await closeTask;
115113
}
116-
117-
private static void LogWarning(ITestOutputHelper output, string text,
118-
[CallerFilePath] string file = "",
119-
[CallerMemberName] string member = "",
120-
[CallerLineNumber] int line = 0)
121-
{
122-
// https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-a-warning-message
123-
output.WriteLine($"::warning file={0},line={1}::{2} {3}",
124-
Path.GetFileName(file), line, member, text);
125-
}
126114
}
127115
}

0 commit comments

Comments
 (0)