Compare commits

...

3 Commits

Author SHA1 Message Date
Jimmy Rasmussen
abdfe396d2 Add test cases to ensure default boto session is not used 2020-10-16 11:20:59 -04:00
Jimmy Rasmussen
dec875975b Give each redshift client their own boto session
since the boto session is not thread-safe, using the default session in a multi-threaded scenario will result in concurrency errors
2020-10-16 11:17:59 -04:00
Jacob Beck
3683889e50 fix the new makefile on macos 2020-10-16 11:16:12 -04:00
3 changed files with 27 additions and 1 deletions

View File

@@ -24,8 +24,13 @@ test-quick: .env
# This rule creates a file named .env that is used by docker-compose for passing
# the USER_ID and GROUP_ID arguments to the Docker image.
.env:
@touch .env
ifneq ($(OS),Windows_NT)
ifneq ($(shell uname -s), Darwin)
@echo USER_ID=$(shell id -u) > .env
@echo GROUP_ID=$(shell id -g) >> .env
endif
endif
@time docker-compose build
clean:

View File

@@ -99,7 +99,8 @@ class RedshiftConnectionManager(PostgresConnectionManager):
must already exist in the database, or else an error will occur"""
if iam_profile is None:
boto_client = boto3.client('redshift')
session = boto3.Session()
boto_client = session.client("redshift")
else:
logger.debug("Connecting to Redshift using 'IAM'" +
f"with profile {iam_profile}")

View File

@@ -1,6 +1,9 @@
import unittest
from unittest import mock
from unittest.mock import Mock
import agate
import boto3
import dbt.adapters # noqa
import dbt.flags as flags
@@ -129,6 +132,23 @@ class TestRedshiftAdapter(unittest.TestCase):
self.assertTrue("'cluster_id' must be provided" in context.exception.msg)
def test_default_session_is_not_used_when_iam_used(self):
boto3.DEFAULT_SESSION = Mock()
self.config.credentials = self.config.credentials.replace(method='iam')
self.config.credentials.cluster_id = 'clusterid'
with mock.patch('dbt.adapters.redshift.connections.boto3.Session'):
RedshiftAdapter.ConnectionManager.get_credentials(self.config.credentials)
self.assertEquals(boto3.DEFAULT_SESSION.client.call_count, 0,
"The redshift client should not be created using the default session because the session object is not thread-safe")
def test_default_session_is_not_used_when_iam_not_used(self):
boto3.DEFAULT_SESSION = Mock()
self.config.credentials = self.config.credentials.replace(method=None)
with mock.patch('dbt.adapters.redshift.connections.boto3.Session'):
RedshiftAdapter.ConnectionManager.get_credentials(self.config.credentials)
self.assertEquals(boto3.DEFAULT_SESSION.client.call_count, 0,
"The redshift client should not be created using the default session because the session object is not thread-safe")
def test_cancel_open_connections_empty(self):
self.assertEqual(len(list(self.adapter.cancel_open_connections())), 0)