Skip to content

Commit 7bc86d1

Browse files
committed
fix tests
1 parent 717ca49 commit 7bc86d1

File tree

8 files changed

+75
-71
lines changed

8 files changed

+75
-71
lines changed

Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace Microsoft.Azure.Cosmos
1313
using System.Text;
1414
using System.Threading;
1515
using System.Threading.Tasks;
16+
using HdrHistogram;
1617
using Microsoft.Azure.Cosmos.Handlers;
1718
using Microsoft.Azure.Cosmos.Resource.CosmosExceptions;
1819
using Microsoft.Azure.Cosmos.Routing;
@@ -501,12 +502,15 @@ private async Task<TResult> RunWithDiagnosticsHelperAsync<TResult>(
501502
RequestOptions requestOptions,
502503
ResourceType? resourceType = null)
503504
{
504-
if (resourceType is not null && this.IsBulkOperationSupported(resourceType.Value, operationType))
505+
OpenTelemetryCoreRecorder? recorder = null;
506+
try
505507
{
506-
operationName = OpenTelemetryConstants.Operations.ExecuteBulkPrefix + operationName;
507-
}
508+
if (resourceType is not null && this.IsBulkOperationSupported(resourceType.Value, operationType))
509+
{
510+
operationName = OpenTelemetryConstants.Operations.ExecuteBulkPrefix + operationName;
511+
}
508512

509-
using (OpenTelemetryCoreRecorder recorder =
513+
using (recorder =
510514
OpenTelemetryRecorderFactory.CreateRecorder(
511515
operationName: operationName,
512516
containerName: containerName,
@@ -515,52 +519,53 @@ private async Task<TResult> RunWithDiagnosticsHelperAsync<TResult>(
515519
requestOptions: requestOptions,
516520
trace: trace,
517521
clientContext: this.isDisposed ? null : this))
518-
using (new ActivityScope(Guid.NewGuid()))
519-
{
520-
try
521522
{
522-
TResult result = await task(trace).ConfigureAwait(false);
523-
if (openTelemetry != null && recorder.IsEnabled)
523+
using (new ActivityScope(Guid.NewGuid()))
524524
{
525-
// Record request response information
526-
OpenTelemetryAttributes response = openTelemetry(result);
527-
recorder.Record(response);
528-
}
525+
TResult result = await task(trace).ConfigureAwait(false);
526+
if (openTelemetry != null && recorder != null && recorder.Value.IsEnabled)
527+
{
528+
// Record request response information
529+
OpenTelemetryAttributes response = openTelemetry(result);
530+
recorder?.Record(response);
531+
}
529532

530-
return result;
531-
}
532-
catch (OperationCanceledException oe) when (!(oe is CosmosOperationCanceledException))
533-
{
534-
CosmosOperationCanceledException operationCancelledException = new CosmosOperationCanceledException(oe, trace);
535-
recorder.MarkFailed(operationCancelledException);
536-
537-
throw operationCancelledException;
538-
}
539-
catch (ObjectDisposedException objectDisposed) when (!(objectDisposed is CosmosObjectDisposedException))
540-
{
541-
CosmosObjectDisposedException objectDisposedException = new CosmosObjectDisposedException(
542-
objectDisposed,
543-
this.client,
544-
trace);
545-
recorder.MarkFailed(objectDisposedException);
533+
return result;
546534

547-
throw objectDisposedException;
535+
}
548536
}
549-
catch (NullReferenceException nullRefException) when (!(nullRefException is CosmosNullReferenceException))
550-
{
551-
CosmosNullReferenceException nullException = new CosmosNullReferenceException(
552-
nullRefException,
553-
trace);
554-
recorder.MarkFailed(nullException);
537+
}
538+
catch (OperationCanceledException oe) when (!(oe is CosmosOperationCanceledException))
539+
{
540+
CosmosOperationCanceledException operationCancelledException = new CosmosOperationCanceledException(oe, trace);
541+
recorder?.MarkFailed(operationCancelledException);
555542

556-
throw nullException;
557-
}
558-
catch (Exception ex)
559-
{
560-
recorder.MarkFailed(ex);
543+
throw operationCancelledException;
544+
}
545+
catch (ObjectDisposedException objectDisposed) when (!(objectDisposed is CosmosObjectDisposedException))
546+
{
547+
CosmosObjectDisposedException objectDisposedException = new CosmosObjectDisposedException(
548+
objectDisposed,
549+
this.client,
550+
trace);
551+
recorder?.MarkFailed(objectDisposedException);
561552

562-
throw;
563-
}
553+
throw objectDisposedException;
554+
}
555+
catch (NullReferenceException nullRefException) when (!(nullRefException is CosmosNullReferenceException))
556+
{
557+
CosmosNullReferenceException nullException = new CosmosNullReferenceException(
558+
nullRefException,
559+
trace);
560+
recorder?.MarkFailed(nullException);
561+
562+
throw nullException;
563+
}
564+
catch (Exception ex)
565+
{
566+
recorder?.MarkFailed(ex);
567+
568+
throw;
564569
}
565570
}
566571

@@ -585,7 +590,6 @@ private async Task<ResponseMessage> ProcessResourceOperationAsBulkStreamAsync(
585590
resourceStream: streamPayload,
586591
requestOptions: batchItemRequestOptions,
587592
cosmosClientContext: this);
588-
589593
TransactionalBatchOperationResult batchOperationResult = await cosmosContainerCore.BatchExecutor.AddAsync(
590594
itemBatchOperation,
591595
trace,

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Batch/BatchAsyncBatcherTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,10 +763,10 @@ private static CosmosClientContext MockClientContext()
763763
It.IsAny<RequestOptions>(),
764764
It.IsAny<Func<ITrace, Task<object>>>(),
765765
It.IsAny<Func<object, OpenTelemetryAttributes>>(),
766-
It.IsAny<ResourceType>(),
766+
It.IsAny<ResourceType?>(),
767767
It.IsAny<TraceComponent>(),
768768
It.IsAny<TraceLevel>()))
769-
.Returns<string, string, string, OperationType, RequestOptions, Func<ITrace, Task<object>>, Func<object, OpenTelemetryAttributes>, ResourceType, TraceComponent, TraceLevel>(
769+
.Returns<string, string, string, OperationType, RequestOptions, Func<ITrace, Task<object>>, Func<object, OpenTelemetryAttributes>, ResourceType?, TraceComponent, TraceLevel>(
770770
(operationName, containerName, databaseName, operationType,requestOptions, func, oTelFunc, resourceType, comp, level) => func(NoOpTrace.Singleton));
771771

772772
return mockContext.Object;

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Batch/BatchAsyncContainerExecutorTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,10 @@ private Mock<CosmosClientContext> MockClientContext()
351351
It.IsAny<RequestOptions>(),
352352
It.IsAny<Func<ITrace, Task<object>>>(),
353353
It.IsAny<Func<object, OpenTelemetryAttributes>>(),
354-
It.IsAny<ResourceType>(),
354+
It.IsAny<ResourceType?>(),
355355
It.IsAny<TraceComponent>(),
356356
It.IsAny<TraceLevel>()))
357-
.Returns<string, string, string, OperationType, RequestOptions, Func<ITrace, Task<object>>, Func<object, OpenTelemetryAttributes>, ResourceType, TraceComponent, TraceLevel>(
357+
.Returns<string, string, string, OperationType, RequestOptions, Func<ITrace, Task<object>>, Func<object, OpenTelemetryAttributes>, ResourceType?, TraceComponent, TraceLevel>(
358358
(operationName,containerName, databaseName, operationType, requestOptions, func, oTelFunc, resourceType, comp, level) => func(NoOpTrace.Singleton));
359359

360360
mockContext.Setup(x => x.Client).Returns(MockCosmosUtil.CreateMockCosmosClient());

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Batch/BatchAsyncStreamerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,10 @@ private CosmosClientContext GetMockClientContext()
207207
It.IsAny<RequestOptions>(),
208208
It.IsAny<Func<ITrace, Task<object>>>(),
209209
It.IsAny<Func<object, OpenTelemetryAttributes>>(),
210-
It.IsAny<ResourceType>(),
210+
It.IsAny<ResourceType?>(),
211211
It.IsAny<TraceComponent>(),
212212
It.IsAny<TraceLevel>()))
213-
.Returns<string, string, string, OperationType, RequestOptions, Func<ITrace, Task<object>>, Func<object, OpenTelemetryAttributes>, ResourceType, TraceComponent, TraceLevel>(
213+
.Returns<string, string, string, OperationType, RequestOptions, Func<ITrace, Task<object>>, Func<object, OpenTelemetryAttributes>, ResourceType?, TraceComponent, TraceLevel>(
214214
(operationName, containerName, databaseName, operationType, requestOptions, func, oTelFunc, resourceType, comp, level) => func(NoOpTrace.Singleton));
215215

216216
return mockContext.Object;

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/ChangeFeed/ChangeFeedEstimatorIteratorTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,10 @@ static FeedIteratorInternal feedCreator(DocumentServiceLease lease, string conti
392392
It.IsAny<RequestOptions>(),
393393
It.IsAny<Func<ITrace, Task<FeedResponse<ChangeFeedProcessorState>>>>(),
394394
It.IsAny<Func<FeedResponse<ChangeFeedProcessorState>, OpenTelemetryAttributes>>(),
395-
It.IsAny<ResourceType>(),
395+
It.IsAny<ResourceType?>(),
396396
It.Is<TraceComponent>(tc => tc == TraceComponent.ChangeFeed),
397397
It.IsAny<TraceLevel>()))
398-
.Returns<string, string, string, Documents.OperationType, RequestOptions, Func<ITrace, Task<FeedResponse<ChangeFeedProcessorState>>>, Func<FeedResponse<ChangeFeedProcessorState>, OpenTelemetryAttributes>, ResourceType, TraceComponent, TraceLevel>(
398+
.Returns<string, string, string, Documents.OperationType, RequestOptions, Func<ITrace, Task<FeedResponse<ChangeFeedProcessorState>>>, Func<FeedResponse<ChangeFeedProcessorState>, OpenTelemetryAttributes>, ResourceType?, TraceComponent, TraceLevel>(
399399
(operationName, containerName, databaseName, operationType, requestOptions, func, oTelFunc, resourceType, comp, level) =>
400400
{
401401
using (ITrace trace = Trace.GetRootTrace(operationName, comp, level))
@@ -504,10 +504,10 @@ private static ContainerInternal GetMockedContainer()
504504
It.IsAny<RequestOptions>(),
505505
It.IsAny<Func<ITrace, Task<FeedResponse<ChangeFeedProcessorState>>>>(),
506506
It.IsAny<Func<FeedResponse<ChangeFeedProcessorState>, OpenTelemetryAttributes>>(),
507-
It.IsAny<ResourceType>(),
507+
It.IsAny<ResourceType?>(),
508508
It.Is<TraceComponent>(tc => tc == TraceComponent.ChangeFeed),
509509
It.IsAny<TraceLevel>()))
510-
.Returns<string, string, string, Documents.OperationType, RequestOptions, Func<ITrace, Task<FeedResponse<ChangeFeedProcessorState>>>, Func<FeedResponse<ChangeFeedProcessorState>, OpenTelemetryAttributes>, ResourceType, TraceComponent, TraceLevel>(
510+
.Returns<string, string, string, Documents.OperationType, RequestOptions, Func<ITrace, Task<FeedResponse<ChangeFeedProcessorState>>>, Func<FeedResponse<ChangeFeedProcessorState>, OpenTelemetryAttributes>, ResourceType?, TraceComponent, TraceLevel>(
511511
(operationName, containerName, databaseName, operationType, requestOptions, func, oTelFunc, resourceType, comp, level) =>
512512
{
513513
using (ITrace trace = Trace.GetRootTrace(operationName, comp, level))

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/ChangeFeed/ChangeFeedPartitionKeyResultSetIteratorCoreTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ public async Task EtagPassesContinuation()
4949
It.IsAny<RequestOptions>(),
5050
It.IsAny<Func<ITrace, Task<ResponseMessage>>>(),
5151
It.IsAny<Func<ResponseMessage, OpenTelemetryAttributes>>(),
52-
It.IsAny<Documents.ResourceType>(),
52+
It.IsAny<Documents.ResourceType?>(),
5353
It.Is<TraceComponent>(tc => tc == TraceComponent.ChangeFeed),
5454
It.IsAny<TraceLevel>()))
55-
.Returns<string, string, string, Documents.OperationType, RequestOptions, Func<ITrace, Task<ResponseMessage>>,Func<ResponseMessage, OpenTelemetryAttributes>, ResourceType, TraceComponent, TraceLevel>(
55+
.Returns<string, string, string, Documents.OperationType, RequestOptions, Func<ITrace, Task<ResponseMessage>>,Func<ResponseMessage, OpenTelemetryAttributes>, ResourceType?, TraceComponent, TraceLevel>(
5656
(operationName, containerName, databaseName, operationType, requestOptions, func, oTelFunc, resourceType, comp, level) =>
5757
{
5858
using (ITrace trace = Trace.GetRootTrace(operationName, comp, level))
@@ -130,10 +130,10 @@ public async Task NextReadHasUpdatedContinuation()
130130
It.IsAny<RequestOptions>(),
131131
It.IsAny<Func<ITrace, Task<ResponseMessage>>>(),
132132
It.IsAny<Func<ResponseMessage, OpenTelemetryAttributes>>(),
133-
It.IsAny<Documents.ResourceType>(),
133+
It.IsAny<Documents.ResourceType?>(),
134134
It.Is<TraceComponent>(tc => tc == TraceComponent.ChangeFeed),
135135
It.IsAny<TraceLevel>()))
136-
.Returns<string, string, string, Documents.OperationType, RequestOptions, Func<ITrace, Task<ResponseMessage>>, Func<ResponseMessage, OpenTelemetryAttributes>, ResourceType, TraceComponent, TraceLevel>(
136+
.Returns<string, string, string, Documents.OperationType, RequestOptions, Func<ITrace, Task<ResponseMessage>>, Func<ResponseMessage, OpenTelemetryAttributes>, ResourceType?, TraceComponent, TraceLevel>(
137137
(operationName, containerName, databaseName, operationType, requestOptions, func, oTelFunc, resourceType, comp, level) =>
138138
{
139139
using (ITrace trace = Trace.GetRootTrace(operationName, comp, level))
@@ -201,10 +201,10 @@ public async Task ShouldSetFeedRangePartitionKeyRange()
201201
It.IsAny<RequestOptions>(),
202202
It.IsAny<Func<ITrace, Task<ResponseMessage>>>(),
203203
It.IsAny<Func<ResponseMessage, OpenTelemetryAttributes>>(),
204-
It.IsAny<Documents.ResourceType>(),
204+
It.IsAny<Documents.ResourceType?>(),
205205
It.Is<TraceComponent>(tc => tc == TraceComponent.ChangeFeed),
206206
It.IsAny<TraceLevel>()))
207-
.Returns<string, string, string, Documents.OperationType, RequestOptions, Func<ITrace, Task<ResponseMessage>>, Func<ResponseMessage, OpenTelemetryAttributes>, ResourceType, TraceComponent, TraceLevel>(
207+
.Returns<string, string, string, Documents.OperationType, RequestOptions, Func<ITrace, Task<ResponseMessage>>, Func<ResponseMessage, OpenTelemetryAttributes>, ResourceType?, TraceComponent, TraceLevel>(
208208
(operationName, containerName, databaseName, operationType, requestOptions, func, oTelFunc, resourceType, comp, level) =>
209209
{
210210
using (ITrace trace = Trace.GetRootTrace(operationName, comp, level))
@@ -284,10 +284,10 @@ public async Task ShouldUseFeedRangeEpk()
284284
It.IsAny<RequestOptions>(),
285285
It.IsAny<Func<ITrace, Task<ResponseMessage>>>(),
286286
It.IsAny<Func<ResponseMessage, OpenTelemetryAttributes>>(),
287-
It.IsAny<Documents.ResourceType>(),
287+
It.IsAny<Documents.ResourceType?>(),
288288
It.Is<TraceComponent>(tc => tc == TraceComponent.ChangeFeed),
289289
It.IsAny<TraceLevel>()))
290-
.Returns<string, string, string, Documents.OperationType, RequestOptions, Func<ITrace, Task<ResponseMessage>>, Func<ResponseMessage, OpenTelemetryAttributes>, Documents.ResourceType, TraceComponent, TraceLevel>(
290+
.Returns<string, string, string, Documents.OperationType, RequestOptions, Func<ITrace, Task<ResponseMessage>>, Func<ResponseMessage, OpenTelemetryAttributes>, Documents.ResourceType?, TraceComponent, TraceLevel>(
291291
(operationName, containerName, databaseName, operationType, requestOptions, func, oTelFunc, resourceType, comp, level) =>
292292
{
293293
using (ITrace trace = Trace.GetRootTrace(operationName, comp, level))

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosItemUnitTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -717,11 +717,11 @@ public async Task TestMultipleNestedPartitionKeyValueFromStreamAsync()
717717
It.IsAny<RequestOptions>(),
718718
It.IsAny<Func<ITrace, Task<ResponseMessage>>>(),
719719
It.IsAny<Func<ResponseMessage, OpenTelemetryAttributes>>(),
720-
It.IsAny<ResourceType>(),
720+
It.IsAny<ResourceType?>(),
721721
It.IsAny<TraceComponent>(),
722722
It.IsAny<TraceLevel>()))
723-
.Returns<string, string, string, OperationType, RequestOptions, Func<ITrace, Task<ResponseMessage>>, Func<ResponseMessage, OpenTelemetryAttributes>, TraceComponent, TraceLevel>(
724-
(operationName, containerName, databaseName, operationType, requestOptions, func, oTelFunc, comp, level) => func(NoOpTrace.Singleton));
723+
.Returns<string, string, string, OperationType, RequestOptions, Func<ITrace, Task<ResponseMessage>>, Func<ResponseMessage, OpenTelemetryAttributes>, ResourceType?, TraceComponent, TraceLevel>(
724+
(operationName, containerName, databaseName, operationType, requestOptions, func, oTelFunc, resourceType, comp, level) => func(NoOpTrace.Singleton));
725725

726726
mockContext.Setup(x => x.OperationHelperAsync<ItemResponse<dynamic>>(
727727
It.IsAny<string>(),
@@ -731,11 +731,11 @@ public async Task TestMultipleNestedPartitionKeyValueFromStreamAsync()
731731
It.IsAny<RequestOptions>(),
732732
It.IsAny<Func<ITrace, Task<ItemResponse<dynamic>>>>(),
733733
It.IsAny<Func<ItemResponse<dynamic>, OpenTelemetryAttributes>>(),
734-
It.IsAny<ResourceType>(),
734+
It.IsAny<ResourceType?>(),
735735
It.IsAny<TraceComponent>(),
736736
It.IsAny<TraceLevel>()))
737-
.Returns<string, string, string, OperationType, RequestOptions, Func<ITrace, Task<ItemResponse<dynamic>>>, Func<ItemResponse<dynamic>, OpenTelemetryAttributes>, TraceComponent, TraceLevel>(
738-
(operationName, containerName, databaseName, operationType, requestOptions, func, oTelFunc, comp, level) => func(NoOpTrace.Singleton));
737+
.Returns<string, string, string, OperationType, RequestOptions, Func<ITrace, Task<ItemResponse<dynamic>>>, Func<ItemResponse<dynamic>, OpenTelemetryAttributes>, ResourceType?, TraceComponent, TraceLevel>(
738+
(operationName, containerName, databaseName, operationType, requestOptions, func, oTelFunc, resourceType, comp, level) => func(NoOpTrace.Singleton));
739739

740740
mockContext.Setup(x => x.ProcessResourceOperationStreamAsync(
741741
It.IsAny<string>(),

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/FeedRange/ChangeFeedIteratorCoreTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,11 +483,11 @@ private CosmosClientContext MockClientContext()
483483
It.IsAny<RequestOptions>(),
484484
It.IsAny<Func<ITrace, Task<ResponseMessage>>>(),
485485
It.IsAny<Func<ResponseMessage, OpenTelemetryAttributes>>(),
486-
It.IsAny<ResourceType>(),
486+
It.IsAny<ResourceType?>(),
487487
It.IsAny<TraceComponent>(),
488488
It.IsAny<TraceLevel>()))
489-
.Returns<string, string, string, OperationType, RequestOptions, Func<ITrace, Task<ResponseMessage>>, Func<ResponseMessage, OpenTelemetryAttributes>, TraceComponent, TraceLevel>(
490-
(operationName, containerName, databaseName, operationType, requestOptions, func, oTelFunc, comp, level) => func(NoOpTrace.Singleton));
489+
.Returns<string, string, string, OperationType, RequestOptions, Func<ITrace, Task<ResponseMessage>>, Func<ResponseMessage, OpenTelemetryAttributes>, ResourceType?, TraceComponent, TraceLevel>(
490+
(operationName, containerName, databaseName, operationType, requestOptions, func, oTelFunc, resourceType, comp, level) => func(NoOpTrace.Singleton));
491491

492492
return mockContext.Object;
493493
}

0 commit comments

Comments
 (0)