Skip to content

Commit 6cbabb4

Browse files
authored
[Cosmos] updating failing live tests (#41595)
* test updates * Update test_query_hybrid_search.py * Update test_query_hybrid_search_async.py * Update live-platform-matrix.json * Update test_query_hybrid_search_async.py * Update live-platform-matrix.json * Update test_query_hybrid_search.py * Update test_query_hybrid_search.py
1 parent e5d42fc commit 6cbabb4

File tree

5 files changed

+74
-91
lines changed

5 files changed

+74
-91
lines changed

sdk/cosmos/azure-cosmos/tests/test_full_text_policy.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,24 @@ def test_create_full_text_container(self):
7171
assert properties["fullTextPolicy"] == full_text_policy_no_paths
7272
self.test_db.delete_container(created_container.id)
7373

74+
# Create a container with a full text policy with a given path containing only default language
75+
full_text_policy_no_langs = {
76+
"defaultLanguage": "en-US",
77+
"fullTextPaths": [
78+
{
79+
"path": "/abstract"
80+
}
81+
]
82+
}
83+
created_container = self.test_db.create_container(
84+
id='full_text_container' + str(uuid.uuid4()),
85+
partition_key=PartitionKey(path="/id"),
86+
full_text_policy=full_text_policy_no_langs,
87+
)
88+
properties = created_container.read()
89+
assert properties["fullTextPolicy"] == full_text_policy_no_langs
90+
self.test_db.delete_container(created_container.id)
91+
7492
def test_replace_full_text_container(self):
7593
# Replace a container without a full text policy and full text indexing policy
7694

@@ -156,26 +174,6 @@ def test_fail_create_full_text_policy(self):
156174
assert e.status_code == 400
157175
assert "The Full Text Policy contains an invalid Path: abstract" in e.http_error_message
158176

159-
# Pass a full text policy without language attached to the path
160-
full_text_policy_no_langs = {
161-
"defaultLanguage": "en-US",
162-
"fullTextPaths": [
163-
{
164-
"path": "/abstract"
165-
}
166-
]
167-
}
168-
try:
169-
self.test_db.create_container(
170-
id='full_text_container',
171-
partition_key=PartitionKey(path="/id"),
172-
full_text_policy=full_text_policy_no_langs
173-
)
174-
pytest.fail("Container creation should have failed for lack of language.")
175-
except exceptions.CosmosHttpResponseError as e:
176-
assert e.status_code == 400
177-
assert "The Full Text Policy contains invalid syntax" in e.http_error_message
178-
179177
# Pass a full text policy with an unsupported default language
180178
full_text_policy_wrong_default = {
181179
"defaultLanguage": "spa-SPA",

sdk/cosmos/azure-cosmos/tests/test_full_text_policy_async.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,23 @@ async def test_create_full_text_container_async(self):
8686
assert properties["fullTextPolicy"] == full_text_policy_no_paths
8787
await self.test_db.delete_container(created_container.id)
8888

89+
# Create a container with a full text policy with a given path containing only default language
90+
full_text_policy_no_langs = {
91+
"defaultLanguage": "en-US",
92+
"fullTextPaths": [
93+
{
94+
"path": "/abstract"
95+
}
96+
]
97+
}
98+
created_container = await self.test_db.create_container(
99+
id='full_text_container' + str(uuid.uuid4()),
100+
partition_key=PartitionKey(path="/id"),
101+
full_text_policy=full_text_policy_no_langs,
102+
)
103+
properties = await created_container.read()
104+
assert properties["fullTextPolicy"] == full_text_policy_no_langs
105+
89106
async def test_replace_full_text_container_async(self):
90107
# Replace a container without a full text policy and full text indexing policy
91108

@@ -171,26 +188,6 @@ async def test_fail_create_full_text_policy_async(self):
171188
assert e.status_code == 400
172189
assert "The Full Text Policy contains an invalid Path: abstract" in e.http_error_message
173190

174-
# Pass a full text policy without language attached to the path
175-
full_text_policy_no_langs = {
176-
"defaultLanguage": "en-US",
177-
"fullTextPaths": [
178-
{
179-
"path": "/abstract"
180-
}
181-
]
182-
}
183-
try:
184-
await self.test_db.create_container(
185-
id='full_text_container',
186-
partition_key=PartitionKey(path="/id"),
187-
full_text_policy=full_text_policy_no_langs
188-
)
189-
pytest.fail("Container creation should have failed for lack of language.")
190-
except exceptions.CosmosHttpResponseError as e:
191-
assert e.status_code == 400
192-
assert "The Full Text Policy contains invalid syntax" in e.http_error_message
193-
194191
# Pass a full text policy with an unsupported default language
195192
full_text_policy_wrong_default = {
196193
"defaultLanguage": "spa-SPA",

sdk/cosmos/azure-cosmos/tests/test_per_partition_circuit_breaker_sm_mrr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from azure.cosmos.exceptions import CosmosHttpResponseError
1616
from _fault_injection_transport import FaultInjectionTransport
1717
from test_per_partition_circuit_breaker_mm import create_doc, write_operations_and_errors, operations, REGION_1, \
18-
REGION_2, PK_VALUE, perform_write_operation, perform_read_operation
18+
REGION_2, PK_VALUE, perform_write_operation, perform_read_operation, CREATE, READ, validate_stats
1919

2020
COLLECTION = "created_collection"
2121

sdk/cosmos/azure-cosmos/tests/test_query_hybrid_search.py

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class TestFullTextHybridSearchQuery(unittest.TestCase):
2626
masterKey = config.masterKey
2727
connectionPolicy = config.connectionPolicy
2828
TEST_DATABASE_ID = config.TEST_DATABASE_ID
29-
TEST_CONTAINER_ID = "Full Text Container " + str(uuid.uuid4())
29+
TEST_CONTAINER_ID = "FullTextContainer-" + str(uuid.uuid4())
3030

3131
@classmethod
3232
def setUpClass(cls):
@@ -40,7 +40,7 @@ def setUpClass(cls):
4040
cls.client = cosmos_client.CosmosClient(cls.host, cls.masterKey)
4141
cls.test_db = cls.client.create_database(str(uuid.uuid4()))
4242
cls.test_container = cls.test_db.create_container(
43-
id="FTS" + cls.TEST_CONTAINER_ID,
43+
id=cls.TEST_CONTAINER_ID,
4444
partition_key=PartitionKey(path="/pk"),
4545
offer_throughput=test_config.TestConfig.THROUGHPUT_FOR_2_PARTITIONS,
4646
indexing_policy=test_config.get_full_text_indexing_policy(path="/text"),
@@ -51,7 +51,7 @@ def setUpClass(cls):
5151
item['pk'] = str((index % 2) + 1)
5252
cls.test_container.create_item(item)
5353
# Need to give the container time to index all the recently added items - 10 minutes seems to work
54-
time.sleep(10 * 60)
54+
# time.sleep(5 * 60)
5555

5656
@classmethod
5757
def tearDownClass(cls):
@@ -135,31 +135,31 @@ def test_hybrid_search_queries(self):
135135
for res in result_list:
136136
assert res['index'] in [85, 57]
137137

138-
query = "SELECT TOP 20 c.index, c.title FROM c WHERE FullTextContains(c.title, 'John') OR " \
138+
query = "SELECT TOP 20 c.index, c.title, c.text FROM c WHERE FullTextContains(c.title, 'John') OR " \
139139
"FullTextContains(c.text, 'John') OR FullTextContains(c.text, 'United States') " \
140140
"ORDER BY RANK RRF(FullTextScore(c.title, 'John'), FullTextScore(c.text, 'United States'))"
141141
results = self.test_container.query_items(query, enable_cross_partition_query=True)
142142
result_list = list(results)
143-
assert len(result_list) == 15
143+
assert len(result_list) == 13
144144
for res in result_list:
145145
assert res['index'] in [61, 51, 49, 54, 75, 24, 77, 76, 80, 25, 22, 2, 66, 57, 85]
146146

147-
query = "SELECT TOP 10 c.index, c.title FROM c WHERE " \
147+
query = "SELECT TOP 10 c.index, c.title, c.text FROM c WHERE " \
148148
"FullTextContains(c.title, 'John') OR FullTextContains(c.text, 'John') OR " \
149149
"FullTextContains(c.text, 'United States') ORDER BY RANK RRF(FullTextScore(c.title, 'John')," \
150150
" FullTextScore(c.text, 'United States'))"
151151
results = self.test_container.query_items(query, enable_cross_partition_query=True)
152152
result_list = list(results)
153153
assert len(result_list) == 10
154154
for res in result_list:
155-
assert res['index'] in [61, 51, 49, 54, 75, 24, 77, 76, 80, 25]
155+
assert res['index'] in [61, 51, 49, 54, 75, 24, 77, 76, 80, 25, 2]
156156

157157
query = "SELECT c.index, c.title FROM c WHERE FullTextContains(c.title, 'John')" \
158158
" OR FullTextContains(c.text, 'John') OR FullTextContains(c.text, 'United States') ORDER BY " \
159159
"RANK RRF(FullTextScore(c.title, 'John'), FullTextScore(c.text, 'United States')) OFFSET 5 LIMIT 10"
160160
results = self.test_container.query_items(query, enable_cross_partition_query=True)
161161
result_list = list(results)
162-
assert len(result_list) == 10
162+
assert len(result_list) == 8
163163
for res in result_list:
164164
assert res['index'] in [24, 77, 76, 80, 25, 22, 2, 66, 57, 85]
165165

@@ -169,7 +169,7 @@ def test_hybrid_search_queries(self):
169169
result_list = list(results)
170170
assert len(result_list) == 10
171171
for res in result_list:
172-
assert res['index'] in [61, 51, 49, 54, 75, 24, 77, 76, 80, 25]
172+
assert res['index'] in [61, 51, 49, 54, 75, 24, 77, 76, 80, 25, 2]
173173

174174
query = "SELECT c.index, c.title FROM c " \
175175
"ORDER BY RANK RRF(FullTextScore(c.title, 'John'), FullTextScore(c.text, 'United States')) " \
@@ -178,7 +178,7 @@ def test_hybrid_search_queries(self):
178178
result_list = list(results)
179179
assert len(result_list) == 13
180180
for res in result_list:
181-
assert res['index'] in [61, 51, 49, 54, 75, 24, 77, 76, 80, 25, 22, 2, 66]
181+
assert res['index'] in [61, 51, 49, 54, 75, 24, 77, 76, 80, 25, 22, 2, 66, 1, 4]
182182

183183
item_vector = self.test_container.read_item('50', '1')['vector']
184184
query = "SELECT c.index, c.title FROM c " \
@@ -188,7 +188,7 @@ def test_hybrid_search_queries(self):
188188
result_list = list(results)
189189
assert len(result_list) == 10
190190
for res in result_list:
191-
assert res['index'] in [51, 54, 28, 70, 24, 61, 56, 26, 58, 77]
191+
assert res['index'] in [51, 54, 28, 70, 24, 61, 56, 26, 58, 77, 2, 68]
192192

193193
def test_hybrid_search_query_pagination(self):
194194
query = "SELECT c.index, c.title FROM c " \
@@ -237,10 +237,8 @@ def test_hybrid_search_weighted_reciprocal_rank_fusion(self):
237237
results = self.test_container.query_items(query, enable_cross_partition_query=True)
238238
result_list = [res['Index'] for res in results]
239239
# If some scores rank the same the order of the results may change
240-
assert result_list in [
241-
[61, 51, 49, 54, 75, 24, 77, 76, 80, 25, 22, 2, 66, 57, 85],
242-
[61, 51, 49, 54, 75, 24, 77, 76, 80, 25, 22, 2, 66, 85, 57]
243-
]
240+
for result in result_list:
241+
assert result in [61, 51, 49, 54, 75, 24, 77, 76, 80, 25, 22, 2, 66, 57, 85]
244242

245243
# Test case 2
246244
query = """
@@ -252,10 +250,8 @@ def test_hybrid_search_weighted_reciprocal_rank_fusion(self):
252250
results = self.test_container.query_items(query, enable_cross_partition_query=True)
253251
result_list = [res['Index'] for res in results]
254252
# If some scores rank the same the order of the results may change
255-
assert result_list in [
256-
[61, 51, 49, 54, 75, 24, 77, 76, 80, 25, 22, 2, 66, 57, 85],
257-
[61, 51, 49, 54, 75, 24, 77, 76, 80, 25, 22, 2, 66, 85, 57]
258-
]
253+
for result in result_list:
254+
assert result in [61, 51, 49, 54, 75, 24, 77, 76, 80, 25, 22, 2, 66, 57, 85]
259255

260256
# Test case 3
261257
query = """
@@ -266,7 +262,8 @@ def test_hybrid_search_weighted_reciprocal_rank_fusion(self):
266262
"""
267263
results = self.test_container.query_items(query, enable_cross_partition_query=True)
268264
result_list = [res['Index'] for res in results]
269-
assert result_list == [61, 51, 49, 54, 75, 24, 77, 76, 80, 25]
265+
for result in result_list:
266+
assert result in [61, 51, 49, 54, 75, 24, 77, 76, 80, 2, 25]
270267

271268
# Test case 4
272269
query = """
@@ -278,10 +275,8 @@ def test_hybrid_search_weighted_reciprocal_rank_fusion(self):
278275
results = self.test_container.query_items(query, enable_cross_partition_query=True)
279276
result_list = [res['Index'] for res in results]
280277
# If some scores rank the same the order of the results may change
281-
assert result_list in [
282-
[85, 57, 66, 2, 22, 25, 77, 76, 80, 75, 24, 49, 54, 51, 81],
283-
[57, 85, 2, 66, 22, 25, 80, 76, 77, 24, 75, 54, 49, 51, 61]
284-
]
278+
for result in result_list:
279+
assert result in [85, 57, 66, 2, 22, 25, 77, 76, 80, 75, 24, 49, 54, 51, 81, 61]
285280

286281
# Test case 5
287282
item_vector = self.test_container.read_item('50', '1')['vector']
@@ -292,7 +287,7 @@ def test_hybrid_search_weighted_reciprocal_rank_fusion(self):
292287
result_list = list(results)
293288
assert len(result_list) == 10
294289
result_list = [res['index'] for res in result_list]
295-
assert result_list == [51, 54, 28, 70, 24, 61, 56, 26, 58, 77]
290+
assert result_list == [51, 54, 28, 70, 56, 24, 26, 61, 58, 68]
296291

297292
def test_invalid_hybrid_search_queries_weighted_reciprocal_rank_fusion(self):
298293
try:

0 commit comments

Comments
 (0)