Skip to content

Commit

Permalink
update polling interval per service recommendation (#26297)
Browse files Browse the repository at this point in the history
  • Loading branch information
kristapratico authored Sep 22, 2022
1 parent 0a3b45c commit b7953bc
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
from azure.core.pipeline.policies import AzureKeyCredentialPolicy
from ._client import ConversationAnalysisClient as GeneratedConversationAnalysisClient

POLLING_INTERVAL_DEFAULT = 5


def _authentication_policy(credential):
authentication_policy = None
Expand Down Expand Up @@ -85,6 +87,7 @@ def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, TokenCre
endpoint=endpoint,
credential=credential, # type: ignore
authentication_policy=kwargs.pop("authentication_policy", _authentication_policy(credential)),
polling_interval=kwargs.pop("polling_interval", POLLING_INTERVAL_DEFAULT),
**kwargs
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from azure.core.credentials_async import AsyncTokenCredential
from azure.core.pipeline.policies import AzureKeyCredentialPolicy
from ._client import ConversationAnalysisClient as GeneratedConversationAnalysisClient
from .._patch import POLLING_INTERVAL_DEFAULT


def _authentication_policy(credential):
Expand Down Expand Up @@ -88,6 +89,7 @@ def __init__(
endpoint=endpoint,
credential=credential, # type: ignore
authentication_policy=kwargs.pop("authentication_policy", _authentication_policy(credential)),
polling_interval=kwargs.pop("polling_interval", POLLING_INTERVAL_DEFAULT),
**kwargs
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from azure.core.pipeline.policies import AzureKeyCredentialPolicy
from ._client import ConversationAuthoringClient as GeneratedConversationAuthoringClient

POLLING_INTERVAL_DEFAULT = 5


def _authentication_policy(credential):
authentication_policy = None
Expand Down Expand Up @@ -62,6 +64,7 @@ def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, TokenCre
endpoint=endpoint,
credential=credential, # type: ignore
authentication_policy=kwargs.pop("authentication_policy", _authentication_policy(credential)),
polling_interval=kwargs.pop("polling_interval", POLLING_INTERVAL_DEFAULT),
**kwargs
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from azure.core.credentials_async import AsyncTokenCredential
from azure.core.pipeline.policies import AzureKeyCredentialPolicy
from ._client import ConversationAuthoringClient as GeneratedConversationAuthoringClient
from .._patch import POLLING_INTERVAL_DEFAULT


def _authentication_policy(credential):
Expand Down Expand Up @@ -65,6 +66,7 @@ def __init__(
endpoint=endpoint,
credential=credential, # type: ignore
authentication_policy=kwargs.pop("authentication_policy", _authentication_policy(credential)),
polling_interval=kwargs.pop("polling_interval", POLLING_INTERVAL_DEFAULT),
**kwargs
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from azure.core.credentials import AzureKeyCredential
from azure.ai.language.conversations.authoring import ConversationAuthoringClient
from devtools_testutils import AzureRecordedTestCase


class TestConversationAuthoring(AzureRecordedTestCase):

def test_polling_interval(self, conversation_creds):
# test default
client = ConversationAuthoringClient(conversation_creds["endpoint"], AzureKeyCredential(conversation_creds["key"]))
assert client._config.polling_interval == 5
# test override
client = ConversationAuthoringClient(conversation_creds["endpoint"], AzureKeyCredential(conversation_creds["key"]), polling_interval=1)
assert client._config.polling_interval == 1

def test_authoring_aad(self, recorded_test, conversation_creds):
token = self.get_credential(ConversationAuthoringClient)
client = ConversationAuthoringClient(conversation_creds["endpoint"], token, api_version="2022-05-01")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@
# Licensed under the MIT License.
# ------------------------------------
import pytest

from azure.core.credentials import AzureKeyCredential
from azure.ai.language.conversations.authoring.aio import ConversationAuthoringClient
from devtools_testutils import AzureRecordedTestCase


class TestConversationAuthoringAsync(AzureRecordedTestCase):

def test_polling_interval(self, conversation_creds):
# test default
client = ConversationAuthoringClient(conversation_creds["endpoint"], AzureKeyCredential(conversation_creds["key"]))
assert client._config.polling_interval == 5
# test override
client = ConversationAuthoringClient(conversation_creds["endpoint"], AzureKeyCredential(conversation_creds["key"]), polling_interval=1)
assert client._config.polling_interval == 1

@pytest.mark.asyncio
async def test_authoring_aad(self, recorded_test, conversation_creds):
token = self.get_credential(ConversationAuthoringClient, is_async=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@

class TestConversationalSummarization(AzureRecordedTestCase):

def test_polling_interval(self, conversation_creds):
# test default
client = ConversationAnalysisClient(conversation_creds["endpoint"], AzureKeyCredential(conversation_creds["key"]))
assert client._config.polling_interval == 5
# test override
client = ConversationAnalysisClient(conversation_creds["endpoint"], AzureKeyCredential(conversation_creds["key"]), polling_interval=1)
assert client._config.polling_interval == 1

def test_conversational_summarization(self, recorded_test, conversation_creds):
# analyze query
client = ConversationAnalysisClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@

class TestConversationalSummarizationAsync(AzureRecordedTestCase):

def test_polling_interval(self, conversation_creds):
# test default
client = ConversationAnalysisClient(conversation_creds["endpoint"], AzureKeyCredential(conversation_creds["key"]))
assert client._config.polling_interval == 5
# test override
client = ConversationAnalysisClient(conversation_creds["endpoint"], AzureKeyCredential(conversation_creds["key"]), polling_interval=1)
assert client._config.polling_interval == 1

@pytest.mark.asyncio
async def test_conversational_summarization(self, recorded_test, conversation_creds):
# analyze query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from azure.core.pipeline.policies import AzureKeyCredentialPolicy, BearerTokenCredentialPolicy
from ._client import QuestionAnsweringAuthoringClient as QuestionAnsweringAuthoringClientGenerated

POLLING_INTERVAL_DEFAULT = 5


def _authentication_policy(credential, **kwargs):
if credential is None:
Expand Down Expand Up @@ -61,6 +63,7 @@ def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, TokenCre
endpoint=endpoint,
credential=credential, # type: ignore
authentication_policy=kwargs.pop("authentication_policy", _authentication_policy(credential, **kwargs)),
polling_interval=kwargs.pop("polling_interval", POLLING_INTERVAL_DEFAULT),
**kwargs
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from azure.core.credentials_async import AsyncTokenCredential
from azure.core.pipeline.policies import AzureKeyCredentialPolicy, AsyncBearerTokenCredentialPolicy
from ._client import QuestionAnsweringAuthoringClient as QuestionAnsweringAuthoringClientGenerated
from .._patch import POLLING_INTERVAL_DEFAULT


def _authentication_policy(credential, **kwargs):
Expand Down Expand Up @@ -64,6 +65,7 @@ def __init__(
endpoint=endpoint,
credential=credential, # type: ignore
authentication_policy=kwargs.pop("authentication_policy", _authentication_policy(credential, **kwargs)),
polling_interval=kwargs.pop("polling_interval", POLLING_INTERVAL_DEFAULT),
**kwargs
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@

class TestCreateAndDeploy(QuestionAnsweringTestCase):

def test_polling_interval(self, qna_creds):
# test default
client = QuestionAnsweringAuthoringClient(qna_creds["qna_endpoint"], AzureKeyCredential(qna_creds["qna_key"]))
assert client._config.polling_interval == 5
# test override
client = QuestionAnsweringAuthoringClient(qna_creds["qna_endpoint"], AzureKeyCredential(qna_creds["qna_key"]), polling_interval=1)
assert client._config.polling_interval == 1

def test_create_project_aad(self, recorded_test, qna_creds):
token = self.get_credential(QuestionAnsweringAuthoringClient)
client = QuestionAnsweringAuthoringClient(qna_creds["qna_endpoint"], token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@

class TestCreateAndDeployAsync(QuestionAnsweringTestCase):

def test_polling_interval(self, qna_creds):
# test default
client = QuestionAnsweringAuthoringClient(qna_creds["qna_endpoint"], AzureKeyCredential(qna_creds["qna_key"]))
assert client._config.polling_interval == 5
# test override
client = QuestionAnsweringAuthoringClient(qna_creds["qna_endpoint"], AzureKeyCredential(qna_creds["qna_key"]), polling_interval=1)
assert client._config.polling_interval == 1

@pytest.mark.asyncio
async def test_create_project_aad(self, recorded_test, qna_creds):
token = self.get_credential(QuestionAnsweringAuthoringClient, is_async=True)
Expand Down

0 comments on commit b7953bc

Please sign in to comment.