From 080f87bb04a9ad914f9b3db8c68c491022cf1c22 Mon Sep 17 00:00:00 2001 From: Sourabh Jain Date: Mon, 26 Aug 2024 08:02:55 +0530 Subject: [PATCH] fix tests --- .../CFP/AllVersionsAndDeletes/BuilderTests.cs | 3 ++- .../BuilderWithCustomSerializerTests.cs | 3 ++- .../ChangeFeed/DynamicStreamTests.cs | 3 ++- .../ChangeFeed/DynamicTests.cs | 3 ++- .../CosmosDatabaseTests.cs | 3 ++- .../CosmosNullReferenceExceptionTests.cs | 7 ++++--- .../ChangeFeedPartitionKeyResultSetIteratorCoreTests.cs | 9 +++++---- 7 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CFP/AllVersionsAndDeletes/BuilderTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CFP/AllVersionsAndDeletes/BuilderTests.cs index 669c6bd194..a610e75b7f 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CFP/AllVersionsAndDeletes/BuilderTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CFP/AllVersionsAndDeletes/BuilderTests.cs @@ -14,6 +14,7 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests.CFP.AllVersionsAndDeletes using Microsoft.Azure.Cosmos.ChangeFeed.Utils; using Microsoft.Azure.Cosmos.SDK.EmulatorTests.ChangeFeed; using Microsoft.Azure.Cosmos.Services.Management.Tests; + using Microsoft.Azure.Cosmos.Telemetry.OpenTelemetry; using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -188,7 +189,7 @@ public async Task WhenADocumentIsCreatedThenUpdatedThenDeletedTestsAsync() Assert.IsNotNull(context.Headers); Assert.IsNotNull(context.Headers.Session); Assert.IsTrue(context.Headers.RequestCharge > 0); - Assert.IsTrue(context.Diagnostics.ToString().Contains("Change Feed Processor Read Next Async")); + Assert.IsTrue(context.Diagnostics.ToString().Contains(OpenTelemetryConstants.Operations.QueryChangeFeedForPartitionKeyRange)); Assert.AreEqual(expected: 3, actual: docs.Count); ChangeFeedItem createChange = docs.ElementAt(0); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CFP/AllVersionsAndDeletes/BuilderWithCustomSerializerTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CFP/AllVersionsAndDeletes/BuilderWithCustomSerializerTests.cs index a6780e4409..4f68205673 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CFP/AllVersionsAndDeletes/BuilderWithCustomSerializerTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CFP/AllVersionsAndDeletes/BuilderWithCustomSerializerTests.cs @@ -16,6 +16,7 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests.CFP.AllVersionsAndDeletes using Microsoft.Azure.Cosmos.ChangeFeed.Utils; using Microsoft.Azure.Cosmos.SDK.EmulatorTests.ChangeFeed; using Microsoft.Azure.Cosmos.Services.Management.Tests; + using Microsoft.Azure.Cosmos.Telemetry.OpenTelemetry; using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -539,7 +540,7 @@ public async Task WhenADocumentIsCreatedThenUpdatedThenDeletedTestsAsync(bool pr Assert.IsNotNull(context.Headers); Assert.IsNotNull(context.Headers.Session); Assert.IsTrue(context.Headers.RequestCharge > 0); - Assert.IsTrue(context.Diagnostics.ToString().Contains("Change Feed Processor Read Next Async")); + Assert.IsTrue(context.Diagnostics.ToString().Contains(OpenTelemetryConstants.Operations.QueryChangeFeedForPartitionKeyRange)); Assert.AreEqual(expected: 3, actual: docs.Count); ChangeFeedItem createChange = docs.ElementAt(0); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ChangeFeed/DynamicStreamTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ChangeFeed/DynamicStreamTests.cs index f63ef4dbda..b187a4a4a2 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ChangeFeed/DynamicStreamTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ChangeFeed/DynamicStreamTests.cs @@ -11,6 +11,7 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests.ChangeFeed using System.Threading; using System.Threading.Tasks; using Microsoft.Azure.Cosmos.Scripts; + using Microsoft.Azure.Cosmos.Telemetry.OpenTelemetry; using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -319,7 +320,7 @@ private void ValidateContext(ChangeFeedProcessorContext changeFeedProcessorConte Assert.IsNotNull(changeFeedProcessorContext.Headers.Session); Assert.IsTrue(changeFeedProcessorContext.Headers.RequestCharge > 0); string diagnosticsAsString = changeFeedProcessorContext.Diagnostics.ToString(); - Assert.IsTrue(diagnosticsAsString.Contains("Change Feed Processor Read Next Async")); + Assert.IsTrue(diagnosticsAsString.Contains(OpenTelemetryConstants.Operations.QueryChangeFeedForPartitionKeyRange)); } } } \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ChangeFeed/DynamicTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ChangeFeed/DynamicTests.cs index 02d2faac54..ccb17311b3 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ChangeFeed/DynamicTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ChangeFeed/DynamicTests.cs @@ -10,6 +10,7 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests.ChangeFeed using System.Threading; using System.Threading.Tasks; using Microsoft.Azure.Cosmos.Scripts; + using Microsoft.Azure.Cosmos.Telemetry.OpenTelemetry; using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json; @@ -377,7 +378,7 @@ private async Task ValidateContextAsync(ChangeFeedProcessorContext changeFeedPro Assert.IsNotNull(changeFeedProcessorContext.Headers.Session); Assert.IsTrue(changeFeedProcessorContext.Headers.RequestCharge > 0); string diagnosticsAsString = changeFeedProcessorContext.Diagnostics.ToString(); - Assert.IsTrue(diagnosticsAsString.Contains("Change Feed Processor Read Next Async")); + Assert.IsTrue(diagnosticsAsString.Contains(OpenTelemetryConstants.Operations.QueryChangeFeedForPartitionKeyRange)); await this.ValidateFeedRangeAsync(changeFeedProcessorContext.FeedRange); } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosDatabaseTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosDatabaseTests.cs index ba6d33d55e..7452554a9d 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosDatabaseTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosDatabaseTests.cs @@ -13,6 +13,7 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests using System.Threading.Tasks; using Microsoft.Azure.Cosmos.Core.Trace; using Microsoft.Azure.Cosmos.Resource.CosmosExceptions; + using Microsoft.Azure.Cosmos.Telemetry.OpenTelemetry; using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -217,7 +218,7 @@ public async Task CreateIfNotExists() Assert.IsNotNull(createExistingResponse.Diagnostics); string diagnostics = createExistingResponse.Diagnostics.ToString(); Assert.IsFalse(string.IsNullOrEmpty(diagnostics)); - Assert.IsTrue(diagnostics.Contains("CreateDatabaseIfNotExistsAsync")); + Assert.IsTrue(diagnostics.Contains(OpenTelemetryConstants.Operations.CreateDatabaseIfNotExists)); bool conflictReturned = false; requestHandlerHelper.CallBackOnResponse = (request, response) => diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosNullReferenceExceptionTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosNullReferenceExceptionTests.cs index b91b43fd64..6550805ba4 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosNullReferenceExceptionTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosNullReferenceExceptionTests.cs @@ -8,6 +8,7 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests using System.Threading; using System.Threading.Tasks; using Microsoft.Azure.Cosmos.Diagnostics; + using Microsoft.Azure.Cosmos.Telemetry.OpenTelemetry; using Microsoft.Azure.Documents; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -57,7 +58,7 @@ public async Task CosmosEndToEndNullReferenceExceptionTestAsync() catch(NullReferenceException nre) { Assert.AreEqual(typeof(CosmosNullReferenceException), nre.GetType()); - Assert.IsTrue(nre.Message.Contains("CreateItemAsync")); + Assert.IsTrue(nre.Message.Contains(OpenTelemetryConstants.Operations.CreateItem)); string cosmosToString = nre.ToString(); Assert.IsFalse(cosmosToString.Contains("Microsoft.Azure.Cosmos.CosmosNullReferenceException"), $"The internal wrapper exception should not be exposed to users. {cosmosToString}"); Assert.IsTrue(cosmosToString.Contains(errorMessage)); @@ -73,11 +74,11 @@ public async Task CosmosEndToEndNullReferenceExceptionTestAsync() catch (NullReferenceException nre) { Assert.AreEqual(typeof(CosmosNullReferenceException), nre.GetType()); - Assert.IsTrue(nre.Message.Contains("Typed FeedIterator ReadNextAsync")); + Assert.IsTrue(nre.Message.Contains(OpenTelemetryConstants.Operations.TypedQueryItems)); string cosmosToString = nre.ToString(); Assert.IsFalse(cosmosToString.Contains("Microsoft.Azure.Cosmos.CosmosNullReferenceException"), $"The internal wrapper exception should not be exposed to users. {cosmosToString}"); Assert.IsTrue(cosmosToString.Contains(errorMessage)); - Assert.IsTrue(cosmosToString.Contains("Typed FeedIterator ReadNextAsync")); + Assert.IsTrue(cosmosToString.Contains(OpenTelemetryConstants.Operations.TypedQueryItems)); } } } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/ChangeFeed/ChangeFeedPartitionKeyResultSetIteratorCoreTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/ChangeFeed/ChangeFeedPartitionKeyResultSetIteratorCoreTests.cs index 08baba746b..1d98dc81b1 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/ChangeFeed/ChangeFeedPartitionKeyResultSetIteratorCoreTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/ChangeFeed/ChangeFeedPartitionKeyResultSetIteratorCoreTests.cs @@ -10,6 +10,7 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.Tests using System.Threading.Tasks; using Microsoft.Azure.Cosmos.ChangeFeed.LeaseManagement; using Microsoft.Azure.Cosmos.Telemetry; + using Microsoft.Azure.Cosmos.Telemetry.OpenTelemetry; using Microsoft.Azure.Cosmos.Tests; using Microsoft.Azure.Cosmos.Tracing; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -40,7 +41,7 @@ public async Task EtagPassesContinuation() Mock containerMock = new Mock(); Mock mockContext = new Mock(); mockContext.Setup(x => x.OperationHelperAsync( - It.Is(str => str.Contains("Change Feed Processor")), + It.Is(str => str.Contains(OpenTelemetryConstants.Operations.QueryChangeFeedForPartitionKeyRange)), It.IsAny(), It.IsAny(), It.IsAny(), @@ -120,7 +121,7 @@ public async Task NextReadHasUpdatedContinuation() Mock containerMock = new Mock(); Mock mockContext = new Mock(); mockContext.Setup(x => x.OperationHelperAsync( - It.Is(str => str.Contains("Change Feed Processor")), + It.Is(str => str.Contains(OpenTelemetryConstants.Operations.QueryChangeFeedForPartitionKeyRange)), It.IsAny(), It.IsAny(), It.IsAny(), @@ -190,7 +191,7 @@ public async Task ShouldSetFeedRangePartitionKeyRange() Mock containerMock = new Mock(); Mock mockContext = new Mock(); mockContext.Setup(x => x.OperationHelperAsync( - It.Is(str => str.Contains("Change Feed Processor")), + It.Is(str => str.Contains(OpenTelemetryConstants.Operations.QueryChangeFeedForPartitionKeyRange)), It.IsAny(), It.IsAny(), It.IsAny(), @@ -272,7 +273,7 @@ public async Task ShouldUseFeedRangeEpk() Mock containerMock = new Mock(); Mock mockContext = new Mock(); mockContext.Setup(x => x.OperationHelperAsync( - It.Is(str => str.Contains("Change Feed Processor")), + It.Is(str => str.Contains(OpenTelemetryConstants.Operations.QueryChangeFeedForPartitionKeyRange)), It.IsAny(), It.IsAny(), It.IsAny(),