Skip to content

Commit 2948fbe

Browse files
Fix bug where opening service client with Amqp_WebSocket_Only throws ArgumentOutOfRangeException (#3462)
* use timeout directly * add some tests * remove unused * update dependencies * fixup
1 parent 14a3512 commit 2948fbe

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

e2e/test/iothub/service/ServiceClientE2ETests.cs

+14-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using System.Diagnostics;
6-
using System.Diagnostics.Tracing;
76
using System.Text;
87
using System.Threading.Tasks;
98
using FluentAssertions;
@@ -87,6 +86,20 @@ public async Task ServiceClient_SendsMessage(TransportType transportType)
8786
await sender.SendAsync(testDevice.Id, message).ConfigureAwait(false);
8887
}
8988

89+
[TestMethod]
90+
[Timeout(TestTimeoutMilliseconds)]
91+
[DataRow(TransportType.Amqp)]
92+
[DataRow(TransportType.Amqp_WebSocket_Only)]
93+
public async Task ServiceClient_Open(TransportType transportType)
94+
{
95+
// arrange
96+
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(DevicePrefix).ConfigureAwait(false);
97+
using var client = ServiceClient.CreateFromConnectionString(TestConfiguration.IotHub.ConnectionString, transportType);
98+
99+
// act and expect no exception
100+
await client.OpenAsync().ConfigureAwait(false);
101+
}
102+
90103
// Unfortunately, the way AmqpServiceClient is implemented, it makes mocking the required amqp types difficult
91104
// (the amqp types are private members of the class, and cannot be set from any public/ internal API).
92105
// For this reason the following test is tested in the E2E flow, even though this is a unit test scenario.

iothub/service/src/Messaging/ServiceClient.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using Microsoft.Azure.Amqp;
1111
using Microsoft.Azure.Amqp.Framing;
1212
using Microsoft.Azure.Devices.Common;
13-
using Microsoft.Azure.Devices.Common.Data;
1413
using Microsoft.Azure.Devices.Common.Exceptions;
1514
using Microsoft.Azure.Devices.Shared;
1615

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

293-
using var ctx = new CancellationTokenSource(_openTimeout);
294-
295-
await _faultTolerantSendingLink.OpenAsync(ctx.Token).ConfigureAwait(false);
292+
await _faultTolerantSendingLink.OpenAsync(_openTimeout).ConfigureAwait(false);
296293
await _feedbackReceiver.OpenAsync().ConfigureAwait(false);
297294

298295
if (Logging.IsEnabled)

0 commit comments

Comments
 (0)