Skip to content

Commit

Permalink
update unit test to account for __post_init__
Browse files Browse the repository at this point in the history
  • Loading branch information
mikealfare committed Jul 12, 2024
1 parent 5350962 commit 66ddd96
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions dbt/adapters/snowflake/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ def __post_init__(self):

# only default `reuse_connections` to `True` if the user has not turned on `client_session_keep_alive`
# having both of these set to `True` could lead to hanging open connections, so it should be opt-in behavior
print(f"client_session_keep_alive = {self.client_session_keep_alive}")
print(f"reuse_connections = {self.reuse_connections}")
if self.client_session_keep_alive is False and self.reuse_connections is None:
print("Updating reuse_connections")
self.reuse_connections = True

@property
Expand Down
8 changes: 4 additions & 4 deletions tests/performance/test_auth_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
|---------------|--------------|-------------------|--------------------------------|----------|
| User Password | 1,000 | False | - | 234.09s |
| User Password | 1,000 | True | - | 78.34s |
| Key Pair | 1,000 | False | False | 331.75s |
| Key Pair | 1,000 | False | False | 271.47s | x
| Key Pair | 1,000 | False | True | 278.65s |
| Key Pair | 1,000 | True | False | 75.42s |
| Key Pair | 1,000 | True | False | 63.69s | x
| Key Pair | 1,000 | True | True | 73.14s |
Notes:
Expand Down Expand Up @@ -91,8 +91,8 @@ def auth_params(self):
https://docs.snowflake.com/en/user-guide/key-pair-auth
"""
yield {
"private_key": os.getenv("SNOWFLAKE_PRIVATE_KEY"),
"private_key_passphrase": os.getenv("SNOWFLAKE_PRIVATE_KEY_PASSPHRASE"),
"private_key": os.getenv("SNOWFLAKE_TEST_PRIVATE_KEY"),
"private_key_passphrase": os.getenv("SNOWFLAKE_TEST_PRIVATE_KEY_PASSPHRASE"),
}

else:
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/test_snowflake_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,13 @@ def test_client_session_keep_alive_false_by_default(self):
)

def test_client_session_keep_alive_true(self):
self.config.credentials = self.config.credentials.replace(client_session_keep_alive=True)
self.config.credentials = self.config.credentials.replace(
client_session_keep_alive=True,
# this gets defaulted via `__post_init__` when `client_session_keep_alive` comes in as `False`
# then when `replace` is called, `__post_init__` cannot set it back to `None` since it cannot
# tell the difference between set by user and set by `__post_init__`
reuse_connections=None,
)
self.adapter = SnowflakeAdapter(self.config, get_context("spawn"))
conn = self.adapter.connections.set_connection_name(name="new_connection_with_new_config")

Expand Down

0 comments on commit 66ddd96

Please sign in to comment.