-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SNOW-1720835 param protect thread-safe client side changes #2401
Changes from 42 commits
fb4ecf6
f720701
eca13dc
96949be
5f140ab
0624824
42d6e19
801ad6e
c7fa3ae
5672a1d
bd0528d
39a07d4
4d4e257
5ecb0b4
66374ee
3bec695
d41138a
42ca571
ee3ce32
816b1d9
f1ab835
75bb86c
5e447fd
7e7b47a
a0b259d
97de868
5f9200c
312b5ad
e0bcfb2
4b83442
d1592ba
1d63131
1bde81e
f494010
1de5526
8ed4de4
a155c03
adbc395
56dd2ce
27a667d
eef3568
d22575c
46b3ca8
55844ea
4e481b2
56169c5
d491367
7c6ab40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,10 @@ | |
|
||
import pytest | ||
|
||
from snowflake.snowpark.session import Session | ||
from snowflake.snowpark.session import ( | ||
_PYTHON_SNOWPARK_ENABLE_THREAD_SAFE_SESSION, | ||
Session, | ||
) | ||
from snowflake.snowpark.types import IntegerType | ||
from tests.integ.test_temp_table_cleanup import wait_for_drop_table_sql_done | ||
|
||
|
@@ -32,6 +35,21 @@ | |
from tests.utils import IS_IN_STORED_PROC, IS_LINUX, IS_WINDOWS, TestFiles, Utils | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's use a function scope here to avoid messing with other tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. renamed to threadsafe_session. this would not mess with others, right? |
||
def session( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's call this mutlithread_session instead of session |
||
db_parameters, sql_simplifier_enabled, cte_optimization_enabled, local_testing_mode | ||
): | ||
new_db_parameters = db_parameters.copy() | ||
new_db_parameters["local_testing"] = local_testing_mode | ||
new_db_parameters["session_parameters"] = { | ||
_PYTHON_SNOWPARK_ENABLE_THREAD_SAFE_SESSION: True | ||
} | ||
with Session.builder.configs(new_db_parameters).create() as session: | ||
session._sql_simplifier_enabled = sql_simplifier_enabled | ||
session._cte_optimization_enabled = cte_optimization_enabled | ||
yield session | ||
|
||
|
||
def test_concurrent_select_queries(session): | ||
def run_select(session_, thread_id): | ||
df = session_.sql(f"SELECT {thread_id} as A") | ||
|
@@ -580,3 +598,32 @@ def change_config_value(session_): | |
f"You might have more than one threads sharing the Session object trying to update {config}" | ||
in caplog.text | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("is_enabled", [True, False]) | ||
def test_num_cursors_created(db_parameters, is_enabled, local_testing_mode): | ||
if is_enabled and local_testing_mode: | ||
pytest.skip("Multithreading is enabled by default in local testing mode") | ||
|
||
num_workers = 5 if is_enabled else 1 | ||
new_db_parameters = db_parameters.copy() | ||
new_db_parameters["session_parameters"] = { | ||
_PYTHON_SNOWPARK_ENABLE_THREAD_SAFE_SESSION: is_enabled | ||
} | ||
|
||
with Session.builder.configs(new_db_parameters).create() as new_session: | ||
|
||
def run_query(session_, thread_id): | ||
assert session_.sql(f"SELECT {thread_id} as A").collect()[0][0] == thread_id | ||
|
||
with patch.object( | ||
new_session._conn._telemetry_client, "send_cursor_created_telemetry" | ||
) as mock_telemetry: | ||
with ThreadPoolExecutor(max_workers=num_workers) as executor: | ||
for i in range(10): | ||
executor.submit(run_query, new_session, i) | ||
|
||
# when multithreading is enabled, each worker will create a cursor | ||
# otherwise, we will use the same cursor created by the main thread | ||
# thus creating 0 new cursors. | ||
assert mock_telemetry.call_count == (num_workers if is_enabled else 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how come we have two parameter control here? what are those two ways ?