From feabe705bc4cdc21c663f719a534c201c3bf9c91 Mon Sep 17 00:00:00 2001 From: neon-sunset Date: Wed, 25 Sep 2024 21:34:09 +0300 Subject: [PATCH] test: handle the condition where the namespace is not present in the namespace list if there are no more vectors associated with it --- test/DataTestFixtureBase.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/DataTestFixtureBase.cs b/test/DataTestFixtureBase.cs index 6befa4f..31f3cb9 100644 --- a/test/DataTestFixtureBase.cs +++ b/test/DataTestFixtureBase.cs @@ -6,7 +6,7 @@ public abstract class DataTestFixtureBase : IAsyncLifetime where T : ITransport { public const int MaxAttemptCount = 100; - public const int DelayInterval = 500; + public const int DelayInterval = 250; public abstract string IndexName { get; } public PineconeClient Pinecone { get; private set; } = null!; @@ -120,8 +120,10 @@ public virtual async Task InsertAndWait(IEnumerable vectors, strin public async Task DeleteAndWait(IEnumerable ids, string? indexNamespace = null) { + indexNamespace ??= ""; + var stats = await Index.DescribeStats(); - var vectorCountBefore = stats.Namespaces.Single(x => x.Name == (indexNamespace ?? "")).VectorCount; + var vectorCountBefore = stats.Namespaces.Single(x => x.Name == indexNamespace).VectorCount; var attemptCount = 0; await Index.Delete(ids, indexNamespace); @@ -131,7 +133,13 @@ public async Task DeleteAndWait(IEnumerable ids, string? indexNamespace await Task.Delay(DelayInterval); attemptCount++; stats = await Index.DescribeStats(); - vectorCount = stats.Namespaces.Single(x => x.Name == (indexNamespace ?? "")).VectorCount; + // When using REST transport, it appears that the namespace is no longer returned in the stats + // if the last vector(s) are deleted from it. Here, we handle that by treating it as zero. + vectorCount = stats.Namespaces + .SingleOrDefault( + x => x.Name == indexNamespace, + new() { Name = indexNamespace, VectorCount = 0 }) + .VectorCount; } while (vectorCount > vectorCountBefore - ids.Count() && attemptCount <= MaxAttemptCount); if (vectorCount > vectorCountBefore - ids.Count())