Skip to content

Commit

Permalink
Fix bug where opening service client with Amqp_WebSocket_Only throws …
Browse files Browse the repository at this point in the history
…ArgumentOutOfRangeException (#3462)

* use timeout directly

* add some tests

* remove unused

* update dependencies

* fixup
  • Loading branch information
brycewang-microsoft authored Jun 21, 2024
1 parent 14a3512 commit 2948fbe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
15 changes: 14 additions & 1 deletion e2e/test/iothub/service/ServiceClientE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.Text;
using System.Threading.Tasks;
using FluentAssertions;
Expand Down Expand Up @@ -87,6 +86,20 @@ public async Task ServiceClient_SendsMessage(TransportType transportType)
await sender.SendAsync(testDevice.Id, message).ConfigureAwait(false);
}

[TestMethod]
[Timeout(TestTimeoutMilliseconds)]
[DataRow(TransportType.Amqp)]
[DataRow(TransportType.Amqp_WebSocket_Only)]
public async Task ServiceClient_Open(TransportType transportType)
{
// arrange
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(DevicePrefix).ConfigureAwait(false);
using var client = ServiceClient.CreateFromConnectionString(TestConfiguration.IotHub.ConnectionString, transportType);

// act and expect no exception
await client.OpenAsync().ConfigureAwait(false);
}

// Unfortunately, the way AmqpServiceClient is implemented, it makes mocking the required amqp types difficult
// (the amqp types are private members of the class, and cannot be set from any public/ internal API).
// For this reason the following test is tested in the E2E flow, even though this is a unit test scenario.
Expand Down
5 changes: 1 addition & 4 deletions iothub/service/src/Messaging/ServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Microsoft.Azure.Amqp;
using Microsoft.Azure.Amqp.Framing;
using Microsoft.Azure.Devices.Common;
using Microsoft.Azure.Devices.Common.Data;
using Microsoft.Azure.Devices.Common.Exceptions;
using Microsoft.Azure.Devices.Shared;

Expand Down Expand Up @@ -290,9 +289,7 @@ public virtual async Task OpenAsync()
if (Logging.IsEnabled)
Logging.Enter(this, $"Opening AmqpServiceClient", nameof(OpenAsync));

using var ctx = new CancellationTokenSource(_openTimeout);

await _faultTolerantSendingLink.OpenAsync(ctx.Token).ConfigureAwait(false);
await _faultTolerantSendingLink.OpenAsync(_openTimeout).ConfigureAwait(false);
await _feedbackReceiver.OpenAsync().ConfigureAwait(false);

if (Logging.IsEnabled)
Expand Down

0 comments on commit 2948fbe

Please sign in to comment.