Add test for populateQueryMetrics
@@ -38,10 +38,10 @@ class QueryTest(unittest.TestCase):
collection_options = { 'offerThroughput': 10100 }
created_collection = client.CreateCollection(created_db['_self'], collection_definition, collection_options)
- def test_first_and_last_slashes_trimmed_for_query_string (self):
document_definition = {'pk': 'pk', 'id':'myId'}
created_doc = client.CreateDocument(created_collection['_self'], document_definition)
+ def test_first_and_last_slashes_trimmed_for_query_string (self):
query_options = {'partitionKey': 'pk'}
collectionLink = '/dbs/' + self.testDbName + '/colls/' + self.testCollectionName + '/'
query = 'SELECT * from ' + self.testCollectionName
@@ -50,3 +50,20 @@ class QueryTest(unittest.TestCase):
iter_list = list(query_iterable)
self.assertEqual(iter_list[0]['id'], 'myId')
+ def test_populate_query_metrics (self):
+ query_options = {'partitionKey': 'pk',
+ 'populateQueryMetrics': True}
+ collectionLink = '/dbs/' + self.testDbName + '/colls/' + self.testCollectionName + '/'
+ query = 'SELECT * from ' + self.testCollectionName
+ query_iterable = client.QueryDocuments(collectionLink, query, query_options)
+
+ iter_list = list(query_iterable)
+ self.assertEqual(iter_list[0]['id'], 'myId')
+
+ METRICS_HEADER_NAME = 'x-ms-documentdb-query-metrics'
+ self.assertTrue(METRICS_HEADER_NAME in client.last_response_headers)
+ metrics_header = client.last_response_headers[METRICS_HEADER_NAME]
+ # Validate header is well-formed: "key1=value1;key2=value2;etc"
+ metrics = metrics_header.split(';')
+ self.assertTrue(len(metrics) > 1)
+ self.assertTrue(all(['=' in x for x in metrics]))
