text: # -------------------------------------------------------------------------
  # Copyright (c) Microsoft Corporation. All rights reserved.
  # Licensed under the MIT License. See License.txt in the project root for
  # license information.
  # --------------------------------------------------------------------------
  import asyncio
  import functools
  import json
  from os.path import dirname, join, realpath
  import time
  
  import pytest
  from azure.core.credentials import AzureKeyCredential
  from devtools_testutils import AzureMgmtTestCase, ResourceGroupPreparer
  
  from search_service_preparer import SearchServicePreparer
  
  from azure_devtools.scenario_tests.utilities import trim_kwargs_from_test_function
  
  from azure.core.exceptions import HttpResponseError
  from azure.search.documents.aio import SearchServiceClient
  
  
  def await_prepared_test(test_fn):
      """Synchronous wrapper for async test methods. Used to avoid making changes
      upstream to AbstractPreparer (which doesn't await the functions it wraps)
      """
  
      @functools.wraps(test_fn)
      def run(test_class_instance, *args, **kwargs):
          trim_kwargs_from_test_function(test_fn, kwargs)
          loop = asyncio.get_event_loop()
          return loop.run_until_complete(test_fn(test_class_instance, **kwargs))
  
      return run
  
  
  class SearchIndexClientTest(AzureMgmtTestCase):
      @ResourceGroupPreparer(random_name_enabled=True)
      @SearchServicePreparer()
      @await_prepared_test
      async def test_get_service_statistics(self, api_key, endpoint, **kwargs):
          client = SearchServiceClient(endpoint, AzureKeyCredential(api_key))
          result = await client.get_service_statistics()
          assert isinstance(result, dict)
          assert set(result.keys()) == {"counters", "limits"}
  