Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle test retry for modules #2900

Merged
merged 2 commits into from
Oct 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 8 additions & 23 deletions e2e/test/helpers/TestDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public class TestDevice : IDisposable
{
private const int MaxRetryCount = 20;
private static readonly HashSet<IotHubServiceErrorCode> s_throttlingStatusCodes = new() { IotHubServiceErrorCode.ThrottlingException };
private static readonly HashSet<IotHubServiceErrorCode> s_retryableStatusCodes = new(s_throttlingStatusCodes) { IotHubServiceErrorCode.DeviceNotFound };
private static readonly HashSet<IotHubServiceErrorCode> s_retryableStatusCodes = new(s_throttlingStatusCodes)
{
IotHubServiceErrorCode.DeviceNotFound,
IotHubServiceErrorCode.ModuleNotFound,
drwill-ms marked this conversation as resolved.
Show resolved Hide resolved
};
private static readonly SemaphoreSlim s_semaphore = new(1, 1);

private static readonly IRetryPolicy s_retryPolicy = new IncrementalDelayRetryPolicy(MaxRetryCount, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(3));
Expand Down Expand Up @@ -115,26 +119,7 @@ await RetryOperationHelper
.RetryOperationsAsync(
async () =>
{
try
{
device = await serviceClient.Devices.GetAsync(requestDevice.Id).ConfigureAwait(false);
}
catch (IotHubServiceException ex)
{
s_logger.Trace($"Getting device {requestDevice.Id} threw {ex}");
drwill-ms marked this conversation as resolved.
Show resolved Hide resolved
device = null;
throw;
}

if (device is null)
drwill-ms marked this conversation as resolved.
Show resolved Hide resolved
{
s_logger.Trace($"Getting device {requestDevice.Id} returned null");
throw new IotHubServiceException(
$"Created device {requestDevice.Id} not yet gettable from IoT hub.",
HttpStatusCode.NotFound,
// Using this causes the exception to be retriable, even though a better match would be DeviceNotFound.
IotHubServiceErrorCode.DeviceNotOnline);
}
await serviceClient.Devices.GetAsync(requestDevice.Id).ConfigureAwait(false);
},
s_retryPolicy,
s_retryableStatusCodes,
Expand Down Expand Up @@ -165,7 +150,7 @@ public string ConnectionString
/// <summary>
/// Used in conjunction with DeviceClient.Create()
/// </summary>
public string IotHubHostName => GetHostName(TestConfiguration.IotHub.ConnectionString);
public string IotHubHostName { get; } = GetHostName(TestConfiguration.IotHub.ConnectionString);

/// <summary>
/// Device Id
Expand All @@ -177,7 +162,7 @@ public string ConnectionString
/// </summary>
public Device Device { get; private set; }

public Client.IAuthenticationMethod AuthenticationMethod { get; private set; }
public IAuthenticationMethod AuthenticationMethod { get; private set; }

public IotHubDeviceClient CreateDeviceClient(IotHubClientOptions options = default, ConnectionStringAuthScope authScope = ConnectionStringAuthScope.Device)
{
Expand Down