Skip to content

Commit ae88fe8

Browse files
committed
Fixed delete issue to address data race
1 parent 8e31e13 commit ae88fe8

1 file changed

Lines changed: 31 additions & 27 deletions

File tree

integration/test_collections_sorting.py

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,41 @@
55
@pytest.fixture
66
def sorting_test_client(client_factory: ClientFactory):
77
client = client_factory()
8-
client.collections.delete_all()
9-
yield client
10-
client.collections.delete_all()
11-
client.close()
8+
try:
9+
yield client
10+
finally:
11+
client.close()
1212

1313

1414
def test_collections_list_all_sorting(sorting_test_client):
1515
"""Test that collections.list_all() returns collections sorted alphabetically by key."""
1616

1717
client = sorting_test_client
1818

19-
# Create collections with names in non-alphabetical order
20-
client.collections.create(name="TestCollectionC")
21-
client.collections.create(name="TestCollectionA")
22-
client.collections.create(name="TestCollectionB")
23-
24-
# Get all collections
25-
collections = client.collections.list_all()
26-
27-
# Get the keys and filter only our test collections
28-
collection_keys = list(collections.keys())
29-
test_collections = [k for k in collection_keys if k.startswith("TestCollection")]
30-
31-
# Verify they are in alphabetical order
32-
assert test_collections == sorted(test_collections)
33-
34-
# Test with simple=False as well
35-
collections = client.collections.list_all(simple=False)
36-
collection_keys = list(collections.keys())
37-
test_collections = [k for k in collection_keys if k.startswith("TestCollection")]
38-
assert test_collections == sorted(test_collections)
39-
40-
# Clean up
41-
client.collections.delete(["TestCollectionA", "TestCollectionB", "TestCollectionC"])
19+
try:
20+
# Create collections with names in non-alphabetical order
21+
client.collections.create(name="SortingTestCollectionC")
22+
client.collections.create(name="SortingTestCollectionA")
23+
client.collections.create(name="SortingTestCollectionB")
24+
25+
# Get all collections
26+
collections = client.collections.list_all()
27+
28+
# Get the keys and filter only our test collections
29+
collection_keys = list(collections.keys())
30+
test_collections = [k for k in collection_keys if k.startswith("SortingTestCollection")]
31+
32+
# Verify they are in alphabetical order
33+
assert test_collections == sorted(test_collections)
34+
35+
# Test with simple=False as well
36+
collections = client.collections.list_all(simple=False)
37+
collection_keys = list(collections.keys())
38+
test_collections = [k for k in collection_keys if k.startswith("SortingTestCollection")]
39+
assert test_collections == sorted(test_collections)
40+
41+
finally:
42+
# Clean up
43+
client.collections.delete(
44+
["SortingTestCollectionA", "SortingTestCollectionB", "SortingTestCollectionC"]
45+
)

0 commit comments

Comments
 (0)