Skip to content

Commit ca1616d

Browse files
committed
test(async-indexes): assert auto-resolve on cache miss (CI-0053)
Replaces the stale `test_async_index_factory_requires_prior_describe_rest_async` (which expected PineconeValueError on cache miss) with `test_async_index_factory_auto_resolves_on_cache_miss_rest_async`, which verifies the new behavior introduced in ae44bf8: - cache miss → describe() called → AsyncIndex returned - cache is repopulated after auto-resolve - after delete() polls index gone, cache miss → describe returns 404 → NotFoundError Also removes the now-unused PineconeValueError import. Aligns with unified-index-0024 (revised in harness claims/).
1 parent d0cb408 commit ca1616d

1 file changed

Lines changed: 20 additions & 26 deletions

File tree

‎tests/integration/test_indexes_async.py‎

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from pinecone import AsyncIndex, AsyncPinecone
88
from pinecone.errors import ForbiddenError
9-
from pinecone.errors.exceptions import PineconeValueError
109
from pinecone.models.indexes.index import IndexModel, IndexSpec, IndexStatus
1110
from pinecone.models.indexes.specs import EmbedConfig, IntegratedSpec, ServerlessSpec
1211
from tests.integration.conftest import async_cleanup_resource, unique_name
@@ -533,25 +532,27 @@ async def test_configure_returns_none_and_preserves_deletion_protection_async(
533532

534533
@pytest.mark.integration
535534
@pytest.mark.anyio
536-
async def test_async_index_factory_requires_prior_describe_rest_async(
535+
async def test_async_index_factory_auto_resolves_on_cache_miss_rest_async(
537536
async_client: AsyncPinecone,
538537
) -> None:
539-
"""AsyncPinecone.index(name) raises PineconeValueError when host not cached;
540-
works after describe(); raises again after delete() clears the cache.
538+
"""AsyncPinecone.index(name) auto-resolves the host via describe() on cache miss.
541539
542540
Verifies claims:
543541
- unified-index-0020: Deleting an index removes that index's cached host URL.
544-
- unified-index-0024: The async index client does not auto-fetch the host on
545-
cache miss; it raises PineconeValueError instead.
542+
- unified-index-0024: Both sync and async index clients auto-resolve via
543+
describe() on cache miss; there is no asymmetry between the two.
546544
547545
Sequence:
548546
1. Create index.
549-
2. Call await async_client.index(name) — cache is empty → PineconeValueError.
550-
3. Call await async_client.indexes.describe(name) — populates cache.
551-
4. Call await async_client.index(name) — cache hit → returns AsyncIndex.
552-
5. Delete the index (clears cache, waits for gone).
553-
6. Call await async_client.index(name) — cache miss → PineconeValueError again.
547+
2. Pop the host cache entry to simulate a cold-cache scenario.
548+
3. Call await async_client.index(name) — cache miss → describe is called →
549+
AsyncIndex returned; cache is repopulated.
550+
4. Delete the index (clears cache, polls until gone).
551+
5. Call await async_client.index(name) after deletion — describe returns 404
552+
→ NotFoundError raised.
554553
"""
554+
from pinecone.errors import NotFoundError
555+
555556
name = unique_name("idx")
556557
deleted = False
557558
try:
@@ -565,32 +566,25 @@ async def test_async_index_factory_requires_prior_describe_rest_async(
565566
# create() with timeout polling already populated the cache via describe.
566567
# Clear it to simulate a cold-cache scenario for the factory test.
567568
async_client._host_cache.pop(name, None)
569+
assert name not in async_client._host_cache
568570

569-
# Step 2: cache is empty — async factory raises instead of auto-fetching
570-
# (unlike sync Pinecone.index() which triggers a new describe call)
571-
with pytest.raises(PineconeValueError):
572-
await async_client.index(name=name)
573-
574-
# Step 3: describe() populates the cache as a side effect
575-
await async_client.indexes.describe(name)
576-
assert name in async_client._host_cache, (
577-
"Host must be cached after indexes.describe(name) (unified-index-0019)"
578-
)
579-
580-
# Step 4: cache hit — factory succeeds
571+
# Step 3: cache miss → auto-resolve via describe → AsyncIndex returned
581572
idx = await async_client.index(name=name)
582573
assert isinstance(idx, AsyncIndex)
574+
assert name in async_client._host_cache, (
575+
"Host must be cached after auto-resolve on cache miss (unified-index-0024)"
576+
)
583577

584-
# Step 5: delete clears cache immediately and polls until gone
578+
# Step 4: delete clears cache immediately and polls until gone
585579
await async_client.indexes.delete(name)
586580
deleted = True
587581

588582
assert name not in async_client._host_cache, (
589583
"Host cache must be cleared after delete() (unified-index-0020)"
590584
)
591585

592-
# Step 6: cache miss again → PineconeValueError (no auto-describe in async)
593-
with pytest.raises(PineconeValueError):
586+
# Step 5: cache miss after delete → describe returns 404 → NotFoundError
587+
with pytest.raises(NotFoundError):
594588
await async_client.index(name=name)
595589

596590
finally:

0 commit comments

Comments
 (0)