From 5718a72fe9f380938744ebab930c1e11161a0b5a Mon Sep 17 00:00:00 2001 From: Michael Landis Date: Wed, 13 Dec 2023 20:06:40 -0800 Subject: [PATCH] test: add unique, identifying suffix to each integration test index (#524) In order to debug leaking indexes, we add a unique suffix for each index name. That way we can inspect and identify patterns in leaked resources. --- tests/Integration/Momento.Sdk.Tests/Utils.cs | 13 ++++++++++++- .../Momento.Sdk.Tests/VectorIndexControlTest.cs | 10 +++++----- .../Momento.Sdk.Tests/VectorIndexDataTest.cs | 16 ++++++++-------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/tests/Integration/Momento.Sdk.Tests/Utils.cs b/tests/Integration/Momento.Sdk.Tests/Utils.cs index aa29b081..19f7bffd 100644 --- a/tests/Integration/Momento.Sdk.Tests/Utils.cs +++ b/tests/Integration/Momento.Sdk.Tests/Utils.cs @@ -11,7 +11,18 @@ public static class Utils public static string TestCacheName() => "dotnet-integration-" + NewGuidString(); - public static string TestVectorIndexName() => "dotnet-integration-" + NewGuidString(); + /// + /// Returns a test vector index name that is unique to this test run. + /// + /// + /// This is useful for debugging leaking test vector indexes. + /// + /// A string that uniquely identifies the test, e.g. "test1". + /// A test vector index name that is unique to this test run. + public static string TestVectorIndexName(string meaningfulIdentifier) + { + return $"dotnet-integration-{NewGuidString()}-{meaningfulIdentifier}"; + } public static string NewGuidString() => Guid.NewGuid().ToString(); diff --git a/tests/Integration/Momento.Sdk.Tests/VectorIndexControlTest.cs b/tests/Integration/Momento.Sdk.Tests/VectorIndexControlTest.cs index 72cb8e1e..5b72de83 100644 --- a/tests/Integration/Momento.Sdk.Tests/VectorIndexControlTest.cs +++ b/tests/Integration/Momento.Sdk.Tests/VectorIndexControlTest.cs @@ -21,9 +21,9 @@ public static IEnumerable CreateAndListIndexTestData { return new List { - new object[] { new IndexInfo(Utils.TestVectorIndexName(), 3, SimilarityMetric.CosineSimilarity) }, - new object[] { new IndexInfo(Utils.TestVectorIndexName(), 3, SimilarityMetric.InnerProduct) }, - new object[] { new IndexInfo(Utils.TestVectorIndexName(), 3, SimilarityMetric.EuclideanSimilarity) } + new object[] { new IndexInfo(Utils.TestVectorIndexName("control-create-and-list-1"), 3, SimilarityMetric.CosineSimilarity) }, + new object[] { new IndexInfo(Utils.TestVectorIndexName("control-create-and-list-2"), 3, SimilarityMetric.InnerProduct) }, + new object[] { new IndexInfo(Utils.TestVectorIndexName("control-create-and-list-3"), 3, SimilarityMetric.EuclideanSimilarity) } }; } } @@ -44,7 +44,7 @@ public async Task CreateListDelete_HappyPath(IndexInfo indexInfo) [Fact] public async Task CreateIndexAsync_AlreadyExistsError() { - var indexName = Utils.TestVectorIndexName(); + var indexName = Utils.TestVectorIndexName("control-create-index-already-exists"); const int numDimensions = 3; using (Utils.WithVectorIndex(vectorIndexClient, indexName, numDimensions)) { @@ -79,7 +79,7 @@ public async Task CreateIndexAsync_InvalidNumDimensions() [Fact] public async Task DeleteIndexAsync_DoesntExistError() { - var indexName = Utils.TestVectorIndexName(); + var indexName = Utils.TestVectorIndexName("control-delete-index-doesnt-exist"); var deleteResponse = await vectorIndexClient.DeleteIndexAsync(indexName); Assert.True(deleteResponse is DeleteIndexResponse.Error, $"Unexpected response: {deleteResponse}"); var deleteErr = (DeleteIndexResponse.Error)deleteResponse; diff --git a/tests/Integration/Momento.Sdk.Tests/VectorIndexDataTest.cs b/tests/Integration/Momento.Sdk.Tests/VectorIndexDataTest.cs index dbff9956..2d77356b 100644 --- a/tests/Integration/Momento.Sdk.Tests/VectorIndexDataTest.cs +++ b/tests/Integration/Momento.Sdk.Tests/VectorIndexDataTest.cs @@ -109,7 +109,7 @@ public static IEnumerable UpsertAndSearchTestData public async Task UpsertAndSearch_InnerProduct(SearchDelegate searchDelegate, AssertOnSearchResponse assertOnSearchResponse) { - var indexName = Utils.TestVectorIndexName(); + var indexName = Utils.TestVectorIndexName("data-upsert-and-search-inner-product"); using (Utils.WithVectorIndex(vectorIndexClient, indexName, 2, SimilarityMetric.InnerProduct)) { var items = new List @@ -137,7 +137,7 @@ public async Task UpsertAndSearch_InnerProduct(SearchDelegate searchDelega public async Task UpsertAndSearch_CosineSimilarity(SearchDelegate searchDelegate, AssertOnSearchResponse assertOnSearchResponse) { - var indexName = Utils.TestVectorIndexName(); + var indexName = Utils.TestVectorIndexName("data-upsert-and-search-cosine-similarity"); using (Utils.WithVectorIndex(vectorIndexClient, indexName, 2)) { var items = new List @@ -168,7 +168,7 @@ public async Task UpsertAndSearch_CosineSimilarity(SearchDelegate searchDe public async Task UpsertAndSearch_EuclideanSimilarity(SearchDelegate searchDelegate, AssertOnSearchResponse assertOnSearchResponse) { - var indexName = Utils.TestVectorIndexName(); + var indexName = Utils.TestVectorIndexName("data-upsert-and-search-euclidean-similarity"); using (Utils.WithVectorIndex(vectorIndexClient, indexName, 2, SimilarityMetric.EuclideanSimilarity)) { var items = new List @@ -199,7 +199,7 @@ public async Task UpsertAndSearch_EuclideanSimilarity(SearchDelegate searc public async Task UpsertAndSearch_TopKLimit(SearchDelegate searchDelegate, AssertOnSearchResponse assertOnSearchResponse) { - var indexName = Utils.TestVectorIndexName(); + var indexName = Utils.TestVectorIndexName("data-upsert-and-search-top-k-limit"); using (Utils.WithVectorIndex(vectorIndexClient, indexName, 2, SimilarityMetric.InnerProduct)) { var items = new List @@ -233,7 +233,7 @@ public async Task UpsertAndSearch_TopKLimit(SearchDelegate searchDelegate, public async Task UpsertAndSearch_WithMetadata(SearchDelegate searchDelegate, AssertOnSearchResponse assertOnSearchResponse) { - var indexName = Utils.TestVectorIndexName(); + var indexName = Utils.TestVectorIndexName("data-upsert-and-search-with-metadata"); using (Utils.WithVectorIndex(vectorIndexClient, indexName, 2, SimilarityMetric.InnerProduct)) { var items = new List @@ -305,7 +305,7 @@ public async Task UpsertAndSearch_WithMetadata(SearchDelegate searchDelega public async Task UpsertAndSearch_WithDiverseMetadata(SearchDelegate searchDelegate, AssertOnSearchResponse assertOnSearchResponse) { - var indexName = Utils.TestVectorIndexName(); + var indexName = Utils.TestVectorIndexName("data-upsert-and-search-with-diverse-metadata"); using (Utils.WithVectorIndex(vectorIndexClient, indexName, 2, SimilarityMetric.InnerProduct)) { var metadata = new Dictionary @@ -373,7 +373,7 @@ public async Task UpsertAndSearch_WithDiverseMetadata(SearchDelegate searc public async Task Search_PruneBasedOnThreshold(SimilarityMetric similarityMetric, List scores, List thresholds, SearchDelegate searchDelegate, AssertOnSearchResponse assertOnSearchResponse) { - var indexName = Utils.TestVectorIndexName(); + var indexName = Utils.TestVectorIndexName("data-search-prune-based-on-threshold"); using (Utils.WithVectorIndex(vectorIndexClient, indexName, 2, similarityMetric)) { var items = new List @@ -500,7 +500,7 @@ public static IEnumerable GetItemAndGetItemMetadataTestData [MemberData(nameof(GetItemAndGetItemMetadataTestData))] public async Task GetItemAndGetItemMetadata_HappyPath(GetItemDelegate getItemDelegate, AssertOnGetItemResponse assertOnGetItemResponse, IEnumerable ids, Object expected) { - var indexName = Utils.TestVectorIndexName(); + var indexName = Utils.TestVectorIndexName("data-get-item-and-get-item-metadata-happy-path"); using (Utils.WithVectorIndex(vectorIndexClient, indexName, 2, SimilarityMetric.InnerProduct)) { var items = new List