Skip to content

Commit

Permalink
added subclient test coverage (serviceClient) (#3088)
Browse files Browse the repository at this point in the history
* rebase and digitalTwinsClient tests

* digitalTwinsClient bugs fixed

* query client tests outlines

* query test attempts

* scheduled jobs client and retry policy base fix

* debugged query client tests

* addressed comments p1

* addressed comments p2

* fixes part 2

* fixed retry policy base

* fixes p3

* additional comments

* made location more realistic

* better test names

* final comments addressed
  • Loading branch information
patilsnr authored Feb 15, 2023
1 parent 4a1db93 commit 98aae49
Show file tree
Hide file tree
Showing 7 changed files with 1,207 additions and 31 deletions.
20 changes: 8 additions & 12 deletions iothub/service/src/DigitalTwin/DigitalTwinsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,9 @@ await _internalRetryHandler
}
throw new IotHubServiceException(ex.Message, HttpStatusCode.RequestTimeout, IotHubServiceErrorCode.Unknown, null, ex);
}
catch (Exception ex)
catch (Exception ex) when (Logging.IsEnabled)
{
if (Logging.IsEnabled)
Logging.Error(this, $"Getting digital twin with Id {digitalTwinId} threw an exception: {ex}", nameof(GetAsync));
Logging.Error(this, $"Getting digital twin with Id {digitalTwinId} threw an exception: {ex}", nameof(GetAsync));
throw;
}
finally
Expand Down Expand Up @@ -206,10 +205,9 @@ await _internalRetryHandler
}
throw new IotHubServiceException(ex.Message, HttpStatusCode.RequestTimeout, IotHubServiceErrorCode.Unknown, null, ex);
}
catch (Exception ex)
catch (Exception ex) when (Logging.IsEnabled)
{
if (Logging.IsEnabled)
Logging.Error(this, $"Updating digital twin with Id {digitalTwinId} threw an exception: {ex}", nameof(UpdateAsync));
Logging.Error(this, $"Updating digital twin with Id {digitalTwinId} threw an exception: {ex}", nameof(UpdateAsync));
throw;
}
finally
Expand Down Expand Up @@ -292,10 +290,9 @@ await _internalRetryHandler
}
throw new IotHubServiceException(ex.Message, HttpStatusCode.RequestTimeout, IotHubServiceErrorCode.Unknown, null, ex);
}
catch (Exception ex)
catch (Exception ex) when (Logging.IsEnabled)
{
if (Logging.IsEnabled)
Logging.Error(this, $"Invoking command on digital twin with Id {digitalTwinId} threw an exception: {ex}", nameof(InvokeCommandAsync));
Logging.Error(this, $"Invoking command on digital twin with Id {digitalTwinId} threw an exception: {ex}", nameof(InvokeCommandAsync));
throw;
}
finally
Expand Down Expand Up @@ -381,10 +378,9 @@ await _internalRetryHandler
}
throw new IotHubServiceException(ex.Message, HttpStatusCode.RequestTimeout, IotHubServiceErrorCode.Unknown, null, ex);
}
catch (Exception ex)
catch (Exception ex) when (Logging.IsEnabled)
{
if (Logging.IsEnabled)
Logging.Error(this, $"Invoking component command on digital twin with Id {digitalTwinId} threw an exception: {ex}", nameof(InvokeComponentCommandAsync));
Logging.Error(this, $"Invoking component command on digital twin with Id {digitalTwinId} threw an exception: {ex}", nameof(InvokeComponentCommandAsync));
throw;
}
finally
Expand Down
20 changes: 8 additions & 12 deletions iothub/service/src/Jobs/ScheduledJobsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@ await _internalRetryHandler
}
throw new IotHubServiceException(ex.Message, HttpStatusCode.RequestTimeout, IotHubServiceErrorCode.Unknown, null, ex);
}
catch (Exception ex)
catch (Exception ex) when (Logging.IsEnabled)
{
if (Logging.IsEnabled)
Logging.Error(this, $"Getting job {jobId} threw an exception: {ex}", nameof(GetAsync));
Logging.Error(this, $"Getting job {jobId} threw an exception: {ex}", nameof(GetAsync));
throw;
}
finally
Expand Down Expand Up @@ -182,10 +181,9 @@ await _internalRetryHandler
}
throw new IotHubServiceException(ex.Message, HttpStatusCode.RequestTimeout, IotHubServiceErrorCode.Unknown, null, ex);
}
catch (Exception ex)
catch (Exception ex) when (Logging.IsEnabled)
{
if (Logging.IsEnabled)
Logging.Error(this, $"Canceling job {jobId} threw an exception: {ex}", nameof(CancelAsync));
Logging.Error(this, $"Canceling job {jobId} threw an exception: {ex}", nameof(CancelAsync));
throw;
}
finally
Expand Down Expand Up @@ -264,10 +262,9 @@ await _internalRetryHandler
}
throw new IotHubServiceException(ex.Message, HttpStatusCode.RequestTimeout, IotHubServiceErrorCode.Unknown, null, ex);
}
catch (Exception ex)
catch (Exception ex) when (Logging.IsEnabled)
{
if (Logging.IsEnabled)
Logging.Error(this, $"Scheduling direct method job {scheduledJobsOptions.JobId} threw an exception: {ex}", nameof(ScheduleDirectMethodAsync));
Logging.Error(this, $"Scheduling direct method job {scheduledJobsOptions.JobId} threw an exception: {ex}", nameof(ScheduleDirectMethodAsync));
throw;
}
finally
Expand Down Expand Up @@ -354,10 +351,9 @@ await _internalRetryHandler
}
throw new IotHubServiceException(ex.Message, HttpStatusCode.RequestTimeout, IotHubServiceErrorCode.Unknown, null, ex);
}
catch (Exception ex)
catch (Exception ex) when (Logging.IsEnabled)
{
if (Logging.IsEnabled)
Logging.Error(this, $"Scheduling twin update {scheduledJobsOptions.JobId} threw an exception: {ex}", nameof(ScheduleTwinUpdateAsync));
Logging.Error(this, $"Scheduling twin update {scheduledJobsOptions.JobId} threw an exception: {ex}", nameof(ScheduleTwinUpdateAsync));
throw;
}
finally
Expand Down
10 changes: 4 additions & 6 deletions iothub/service/src/Query/QueryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,9 @@ await _internalRetryHandler
}
throw new IotHubServiceException(ex.Message, HttpStatusCode.RequestTimeout, IotHubServiceErrorCode.Unknown, null, ex);
}
catch (Exception ex)
catch (Exception ex) when (Logging.IsEnabled)
{
if (Logging.IsEnabled)
Logging.Error(this, $"Creating query threw an exception: {ex}", nameof(CreateAsync));
Logging.Error(this, $"Creating query threw an exception: {ex}", nameof(CreateAsync));
throw;
}
finally
Expand Down Expand Up @@ -228,10 +227,9 @@ await _internalRetryHandler
}
throw new IotHubServiceException(ex.Message, HttpStatusCode.RequestTimeout, IotHubServiceErrorCode.Unknown, null, ex);
}
catch (Exception ex)
catch (Exception ex) when (Logging.IsEnabled)
{
if (Logging.IsEnabled)
Logging.Error(this, $"Creating query with jobType: {options?.JobType}, jobStatus: {options?.JobStatus}, pageSize: {options?.PageSize} threw an exception: {ex}", nameof(CreateAsync));
Logging.Error(this, $"Creating query with jobType: {options?.JobType}, jobStatus: {options?.JobStatus}, pageSize: {options?.PageSize} threw an exception: {ex}", nameof(CreateAsync));
throw;
}
finally
Expand Down
Loading

0 comments on commit 98aae49

Please sign in to comment.