Skip to content

Commit

Permalink
Better exception message when a continuation times out
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebakken committed May 1, 2024
1 parent 5325127 commit f34a662
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
8 changes: 5 additions & 3 deletions projects/RabbitMQ.Client/client/impl/AsyncRpcContinuations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public AsyncRpcContinuation(TimeSpan continuationTimeout, CancellationToken canc
{
// Cancellation was successful, does this mean we set a TimeoutException
// in the same manner as BlockingCell used to
tcs.SetException(new TimeoutException("TODO LRB rabbitmq/rabbitmq-dotnet-client#1347"));
string msg = $"operation '{GetType().FullName}' timed out after {continuationTimeout}";
tcs.TrySetException(new TimeoutException(msg));
}
}, _tcs);
#else
Expand All @@ -79,7 +80,8 @@ public AsyncRpcContinuation(TimeSpan continuationTimeout, CancellationToken canc
{
// Cancellation was successful, does this mean we set a TimeoutException
// in the same manner as BlockingCell used to
tcs.SetException(new TimeoutException("TODO LRB rabbitmq/rabbitmq-dotnet-client#1347"));
string msg = $"operation '{GetType().FullName}' timed out after {continuationTimeout}";
tcs.TrySetException(new TimeoutException(msg));
}
}, state: _tcs, useSynchronizationContext: false);
#endif
Expand Down Expand Up @@ -109,7 +111,7 @@ public ConfiguredTaskAwaitable<T>.ConfiguredTaskAwaiter GetAwaiter()

public virtual void HandleChannelShutdown(ShutdownEventArgs reason)
{
_tcs.SetException(new OperationInterruptedException(reason));
_tcs.TrySetException(new OperationInterruptedException(reason));
}

protected virtual void Dispose(bool disposing)
Expand Down
13 changes: 12 additions & 1 deletion projects/Test/Common/IntegrationFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
using System.Linq;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -619,7 +620,7 @@ protected static string GetUniqueString(ushort length)

protected static byte[] GetRandomBody(ushort size = 1024)
{
var body = new byte[size];
byte[] body = new byte[size];
S_Random.NextBytes(body);
return body;
}
Expand All @@ -639,5 +640,15 @@ protected static TaskCompletionSource<bool> PrepareForRecovery(IConnection conn)

return tcs;
}

protected void LogWarning(string text,
[CallerFilePath] string file = "",
[CallerMemberName] string member = "",
[CallerLineNumber] int line = 0)
{
// https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-a-warning-message
_output.WriteLine("::warning file={0},line={1}::{2} {3}",
Path.GetFileName(file), line, member, text);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
//---------------------------------------------------------------------------

using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
Expand Down Expand Up @@ -97,7 +95,7 @@ public async Task TestPublishRpcRightAfterReconnect()
*/
if (a.ShutdownReason.ReplyCode == 406)
{
LogWarning(_output, "FIXME saw code 406");
LogWarning("FIXME saw code 406");
}
}
}
Expand All @@ -106,22 +104,12 @@ public async Task TestPublishRpcRightAfterReconnect()

if (now - start > WaitSpan)
{
LogWarning(_output, $"FIXME test exceeded wait time of {WaitSpan}");
LogWarning($"FIXME test exceeded wait time of {WaitSpan}");
}

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

await closeTask;
}

private static void LogWarning(ITestOutputHelper output, string text,
[CallerFilePath] string file = "",
[CallerMemberName] string member = "",
[CallerLineNumber] int line = 0)
{
// https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-a-warning-message
output.WriteLine($"::warning file={0},line={1}::{2} {3}",
Path.GetFileName(file), line, member, text);
}
}
}

0 comments on commit f34a662

Please sign in to comment.