Receive should not throw timeout exception (#130)
* Update readme.md (#110) Fixed broken links. * ReceiveAsync call should return NULL instead of throwing System.TimeoutException
This commit is contained in:
Родитель
f88469bda4
Коммит
f4eab19935
|
@ -110,6 +110,13 @@ namespace Microsoft.Azure.EventHubs.Amqp
|
|||
}
|
||||
else
|
||||
{
|
||||
// Handle System.TimeoutException explicitly.
|
||||
// We don't really want to to throw TimeoutException on this call.
|
||||
if (ex is TimeoutException)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -748,6 +748,50 @@ namespace Microsoft.Azure.EventHubs.UnitTests
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Small receive timeout should not throw System.TimeoutException.
|
||||
/// TimeoutException should be returned as NULL to the awaiting client.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Fact]
|
||||
async Task SmallReceiveTimeout()
|
||||
{
|
||||
var maxClients = 5;
|
||||
|
||||
// Issue receives with 1 second so that some of the Receive calls will timeout while creating AMQP link.
|
||||
// Even those Receive calls should return NULL instead of bubbling the exception up.
|
||||
var receiveTimeoutInSeconds = 1;
|
||||
|
||||
var tasks = Enumerable.Range(0, maxClients)
|
||||
.Select(async i =>
|
||||
{
|
||||
PartitionReceiver receiver = null;
|
||||
|
||||
try
|
||||
{
|
||||
Log($"Testing with {receiveTimeoutInSeconds} seconds on client {i}.");
|
||||
|
||||
// Start receiving from a future time so that Receive call won't be able to fetch any events.
|
||||
var ehClient = EventHubClient.CreateFromConnectionString(this.EventHubsConnectionString);
|
||||
receiver = ehClient.CreateReceiver(PartitionReceiver.DefaultConsumerGroupName, "0", DateTime.UtcNow.AddMinutes(1));
|
||||
var ed = await receiver.ReceiveAsync(1, TimeSpan.FromSeconds(receiveTimeoutInSeconds));
|
||||
if (ed == null)
|
||||
{
|
||||
Log($"Received NULL from client {i}");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (receiver != null)
|
||||
{
|
||||
await receiver.CloseAsync();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
async Task PartitionKeyValidation()
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче