Skip to content

Commit

Permalink
perf: instantiate a single aiobotocore session
Browse files Browse the repository at this point in the history
  • Loading branch information
hartungstenio committed Oct 22, 2023
1 parent b51a1d2 commit cf07425
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
3 changes: 2 additions & 1 deletion loafer/ext/aws/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

logger = logging.getLogger(__name__)

session = get_session()


class _BotoClient:
boto_service_name = None
Expand All @@ -21,7 +23,6 @@ def __init__(self, **client_options):
}

def get_client(self):
session = get_session()
return session.create_client(self.boto_service_name, **self._client_options)


Expand Down
8 changes: 2 additions & 6 deletions tests/ext/aws/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ def boto_client_sqs(queue_url, sqs_message):

@pytest.fixture
def mock_boto_session_sqs(boto_client_sqs):
mock_session = mock.Mock()
mock_session.create_client.return_value = ClientContextCreator(boto_client_sqs)
return mock.patch("loafer.ext.aws.bases.get_session", return_value=mock_session)
return mock.patch("loafer.ext.aws.bases.session.create_client", return_value=ClientContextCreator(boto_client_sqs))


@pytest.fixture
Expand All @@ -78,6 +76,4 @@ def boto_client_sns(sns_publish, sns_list_topics):

@pytest.fixture
def mock_boto_session_sns(boto_client_sns):
mock_session = mock.Mock()
mock_session.create_client.return_value = ClientContextCreator(boto_client_sns)
return mock.patch("loafer.ext.aws.bases.get_session", return_value=mock_session)
return mock.patch("loafer.ext.aws.bases.session.create_client", return_value=ClientContextCreator(boto_client_sns))

0 comments on commit cf07425

Please sign in to comment.