Skip to content

Commit ed38f84

Browse files
committed
recover to not bind port
1 parent cb0d10d commit ed38f84

File tree

2 files changed

+2
-19
lines changed

2 files changed

+2
-19
lines changed

test/conftest.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from __future__ import annotations
33

44
import os
5-
import socket
65
from contextlib import contextmanager
76
from logging import getLogger
87
from pathlib import Path
@@ -151,15 +150,6 @@ def pytest_runtest_setup(item) -> None:
151150
pytest.skip("Skipping auth test in current environment")
152151

153152

154-
def find_free_port() -> int:
155-
"""Find a free port to avoid conflicts in parallel test environments."""
156-
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
157-
s.bind(("127.0.0.1", 0))
158-
s.listen(1)
159-
port = s.getsockname()[1]
160-
return port
161-
162-
163153
def get_server_parameter_value(connection, parameter_name: str) -> str | None:
164154
"""Get server parameter value, returns None if parameter doesn't exist."""
165155
try:

test/unit/test_oauth_token.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def test_oauth_code_custom_urls(
367367

368368

369369
@pytest.mark.skipolddriver
370-
@patch("snowflake.connector.auth._http_server.AuthHttpServer.DEFAULT_TIMEOUT", 120)
370+
@patch("snowflake.connector.auth._http_server.AuthHttpServer.DEFAULT_TIMEOUT", 30)
371371
def test_oauth_code_local_application_custom_urls_successful_flow(
372372
wiremock_client: WiremockClient,
373373
wiremock_oauth_authorization_code_dir,
@@ -376,8 +376,6 @@ def test_oauth_code_local_application_custom_urls_successful_flow(
376376
monkeypatch,
377377
omit_oauth_urls_check,
378378
) -> None:
379-
from ..conftest import find_free_port
380-
381379
monkeypatch.setenv("SNOWFLAKE_AUTH_SOCKET_REUSE_PORT", "true")
382380

383381
wiremock_client.import_mapping(
@@ -391,10 +389,6 @@ def test_oauth_code_local_application_custom_urls_successful_flow(
391389
wiremock_generic_mappings_dir / "snowflake_disconnect_successful.json"
392390
)
393391

394-
# Use dynamic port to avoid conflicts and higher timeout for all environments
395-
free_port = find_free_port()
396-
oauth_redirect_uri = f"http://localhost:{free_port}/snowflake/oauth-redirect"
397-
398392
with mock.patch("webbrowser.open", new=webbrowser_mock.open):
399393
with mock.patch("secrets.token_urlsafe", return_value="abc123"):
400394
cnx = snowflake.connector.connect(
@@ -407,10 +401,9 @@ def test_oauth_code_local_application_custom_urls_successful_flow(
407401
role="ANALYST",
408402
oauth_token_request_url=f"http://{wiremock_client.wiremock_host}:{wiremock_client.wiremock_http_port}/tokenrequest",
409403
oauth_authorization_url=f"http://{wiremock_client.wiremock_host}:{wiremock_client.wiremock_http_port}/authorization",
410-
oauth_redirect_uri=oauth_redirect_uri,
404+
oauth_redirect_uri="http://localhost:8009/snowflake/oauth-redirect",
411405
host=wiremock_client.wiremock_host,
412406
port=wiremock_client.wiremock_http_port,
413-
external_browser_timeout=120, # Higher timeout for all environments
414407
)
415408

416409
assert cnx, "invalid cnx"

0 commit comments

Comments
 (0)