Skip to content

Commit 10dc010

Browse files
Routing: Fixes test RIDs to use real Cosmos ResourceIds in CollectionCacheTests
Agent-Logs-Url: https://github.com/Azure/azure-cosmos-dotnet-v3/sessions/f3fef78e-9b62-42a7-bb0f-b3161bb7a6a7 Co-authored-by: kirankumarkolli <6880899+kirankumarkolli@users.noreply.github.com>
1 parent cf312a1 commit 10dc010

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ namespace Microsoft.Azure.Cosmos.Tests
1616
[TestClass]
1717
public class CollectionCacheTests
1818
{
19+
// A real collection RID from the existing test suite (same value used in FeedRangeTests
20+
// and CosmosBadReplicaTests). ResourceId.Parse accepts this value, so it exercises the
21+
// actual binary round-trip through the Direct-package parser.
22+
private const string CollectionRid = "ccZ1ANCszwk=";
23+
1924
[TestMethod]
2025
public async Task ResolveCollectionAsync_WithDatabaseRidInResolvedCollectionRid_FallsBackToNameResolution()
2126
{
22-
const string databaseRid = "jy2ekg==";
23-
const string containerRid = "jy2eklxnboe=";
27+
// Derive a real database RID from the known collection RID so that
28+
// ResourceId.TryParse recognises it as a valid (but database-level) RID.
29+
string databaseRid = ResourceId.Parse(CollectionRid).DatabaseId.ToString();
2430

25-
TestCollectionCache cache = new TestCollectionCache(containerRid);
31+
TestCollectionCache cache = new TestCollectionCache(CollectionRid);
2632
using DocumentServiceRequest request = DocumentServiceRequest.CreateFromName(
2733
OperationType.Read,
2834
"dbs/db1/colls/c1/docs/d1",
@@ -36,31 +42,29 @@ public async Task ResolveCollectionAsync_WithDatabaseRidInResolvedCollectionRid_
3642
CancellationToken.None,
3743
NoOpTrace.Singleton);
3844

39-
Assert.AreEqual(containerRid, resolved.ResourceId);
45+
Assert.AreEqual(CollectionRid, resolved.ResourceId);
4046
Assert.AreEqual(1, cache.NameLookupCount);
4147
Assert.AreEqual(0, cache.RidLookupCount);
4248
}
4349

4450
[TestMethod]
4551
public async Task ResolveCollectionAsync_WithCollectionRidInResolvedCollectionRid_UsesRidResolution()
4652
{
47-
const string containerRid = "jy2eklxnboe=";
48-
49-
TestCollectionCache cache = new TestCollectionCache(containerRid);
53+
TestCollectionCache cache = new TestCollectionCache(CollectionRid);
5054
using DocumentServiceRequest request = DocumentServiceRequest.CreateFromName(
5155
OperationType.Read,
5256
"dbs/db1/colls/c1/docs/d1",
5357
ResourceType.Document,
5458
AuthorizationTokenType.PrimaryMasterKey,
5559
null);
56-
request.RequestContext.ResolvedCollectionRid = containerRid;
60+
request.RequestContext.ResolvedCollectionRid = CollectionRid;
5761

5862
ContainerProperties resolved = await cache.ResolveCollectionAsync(
5963
request,
6064
CancellationToken.None,
6165
NoOpTrace.Singleton);
6266

63-
Assert.AreEqual(containerRid, resolved.ResourceId);
67+
Assert.AreEqual(CollectionRid, resolved.ResourceId);
6468
Assert.AreEqual(0, cache.NameLookupCount);
6569
Assert.AreEqual(1, cache.RidLookupCount);
6670
}
@@ -80,7 +84,9 @@ public async Task ResolveCollectionAsync_WithCollectionRidInResolvedCollectionRi
8084
[TestMethod]
8185
public async Task ResolveCollectionAsync_WhenNameResolutionReturnsDatabaseRid_ThrowsInvalidOperation()
8286
{
83-
const string databaseRid = "jy2ekg==";
87+
// Use a real database RID derived from a known collection RID so that
88+
// ResourceId.TryParse recognises it as a database-level RID.
89+
string databaseRid = ResourceId.Parse(CollectionRid).DatabaseId.ToString();
8490

8591
// The mock returns a container whose ResourceId is a database RID — simulating
8692
// a corrupt server response or a stale in-process cache entry.

0 commit comments

Comments
 (0)