Skip to content

Commit 69984d9

Browse files
committed
addressed comments
Signed-off-by: Lior Sventitzky <[email protected]>
1 parent 14177d0 commit 69984d9

13 files changed

+65
-90
lines changed

python/tests/async_tests/conftest.py

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import AsyncGenerator, List, Optional, Union
44

55
import pytest
6+
67
from glide.config import (
78
BackoffStrategy,
89
GlideClientConfiguration,
@@ -15,14 +16,14 @@
1516
from glide.exceptions import ClosingError
1617
from glide.glide_client import GlideClient, GlideClusterClient, TGlideClient
1718
from glide.logger import Logger
18-
from glide.routes import AllNodes
19-
2019
from tests.utils.cluster import ValkeyCluster
2120
from tests.utils.utils import (
2221
DEFAULT_TEST_LOG_LEVEL,
2322
INITIAL_PASSWORD,
2423
NEW_PASSWORD,
2524
USERNAME,
25+
auth_client,
26+
config_set_new_password,
2627
create_client_config,
2728
set_new_acl_username_with_password,
2829
)
@@ -134,41 +135,6 @@ async def create_client(
134135
return await GlideClient.create(config)
135136

136137

137-
async def auth_client(client: TGlideClient, password: str, username: str = "default"):
138-
"""
139-
Authenticates the given TGlideClient server connected. If no username is provided, uses the 'default' user.
140-
"""
141-
if isinstance(client, GlideClient):
142-
return await client.custom_command(["AUTH", username, password])
143-
elif isinstance(client, GlideClusterClient):
144-
return await client.custom_command(
145-
["AUTH", username, password], route=AllNodes()
146-
)
147-
148-
149-
async def config_set_new_password(client: TGlideClient, password):
150-
"""
151-
Sets a new password for the given TGlideClient server connected.
152-
This function updates the server to require a new password.
153-
"""
154-
if isinstance(client, GlideClient):
155-
await client.config_set({"requirepass": password})
156-
elif isinstance(client, GlideClusterClient):
157-
await client.config_set({"requirepass": password}, route=AllNodes())
158-
159-
160-
async def kill_connections(client: TGlideClient):
161-
"""
162-
Kills all connections to the given TGlideClient server connected.
163-
"""
164-
if isinstance(client, GlideClient):
165-
await client.custom_command(["CLIENT", "KILL", "TYPE", "normal"])
166-
elif isinstance(client, GlideClusterClient):
167-
await client.custom_command(
168-
["CLIENT", "KILL", "TYPE", "normal"], route=AllNodes()
169-
)
170-
171-
172138
async def test_teardown(request, cluster_mode: bool, protocol: ProtocolVersion):
173139
"""
174140
Perform teardown tasks such as flushing all data from the cluster.

python/tests/async_tests/test_async_client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
SlotKeyRoute,
8585
SlotType,
8686
)
87-
8887
from tests.async_tests.conftest import create_client
8988
from tests.utils.utils import (
9089
check_function_list_response,

python/tests/async_tests/test_auth.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@
88
from glide.constants import OK
99
from glide.exceptions import RequestError
1010
from glide.glide_client import TGlideClient
11-
12-
from tests.async_tests.conftest import (
13-
auth_client,
14-
config_set_new_password,
15-
kill_connections,
16-
)
1711
from tests.utils.utils import (
1812
NEW_PASSWORD,
1913
USERNAME,
2014
WRONG_PASSWORD,
15+
auth_client,
16+
config_set_new_password,
2117
delete_acl_username_and_password,
18+
kill_connections,
2219
set_new_acl_username_with_password,
2320
)
2421

python/tests/async_tests/test_batch.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
from glide.constants import OK, TResult, TSingleNodeRoute
6262
from glide.glide_client import GlideClient, GlideClusterClient, TGlideClient
6363
from glide.routes import AllNodes, SlotIdRoute, SlotKeyRoute, SlotType
64-
6564
from tests.async_tests.conftest import create_client
6665
from tests.utils.utils import (
6766
check_if_server_version_lt,

python/tests/async_tests/test_pubsub.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from glide.constants import OK
1818
from glide.exceptions import ConfigurationError
1919
from glide.glide_client import GlideClient, GlideClusterClient, TGlideClient
20-
2120
from tests.async_tests.conftest import create_client
2221
from tests.utils.utils import check_if_server_version_lt, get_random_string
2322

python/tests/async_tests/test_read_from_strategy.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from glide.constants import OK
1111
from glide.glide_client import GlideClusterClient
1212
from glide.routes import AllNodes, SlotIdRoute, SlotType
13-
1413
from tests.async_tests.conftest import create_client
1514
from tests.utils.utils import get_first_result
1615

python/tests/async_tests/test_scan.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from glide.exceptions import RequestError
1010
from glide.glide import ClusterScanCursor
1111
from glide.glide_client import GlideClient, GlideClusterClient
12-
1312
from tests.async_tests.conftest import create_client
1413
from tests.utils.cluster import ValkeyCluster
1514
from tests.utils.utils import get_random_string

python/tests/async_tests/tests_server_modules/test_json.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from glide.constants import OK
2222
from glide.exceptions import RequestError
2323
from glide.glide_client import GlideClusterClient, TGlideClient
24-
2524
from tests.async_tests.test_async_client import get_random_string
2625

2726

python/tests/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ def anyio_backend(request):
241241
)
242242

243243
return request.param[0]
244+
245+
244246
@pytest.fixture(autouse=True)
245247
def skip_if_version_below(request):
246248
"""
@@ -254,7 +256,7 @@ async def test_meow_meow(...):
254256
if request.node.get_closest_marker("skip_if_version_below"):
255257
min_version = request.node.get_closest_marker("skip_if_version_below").args[0]
256258
client = create_sync_client(request, False)
257-
try:
259+
try:
258260
if sync_check_if_server_version_lt(client, min_version):
259261
pytest.skip(
260262
reason=f"This feature added in version {min_version}",

python/tests/sync_tests/conftest.py

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Generator, List, Optional
44

55
import pytest
6+
67
from glide.config import (
78
BackoffStrategy,
89
GlideClientConfiguration,
@@ -13,15 +14,18 @@
1314
ServerCredentials,
1415
)
1516
from glide.exceptions import ClosingError
16-
from glide.glide_client import GlideClient, GlideClusterClient
1717
from glide.logger import Logger
18-
from glide.routes import AllNodes
1918
from glide.sync import GlideClient as SyncGlideClient
2019
from glide.sync import GlideClusterClient as SyncGlideClusterClient
2120
from glide.sync import TGlideClient as TSyncGlideClient
22-
2321
from tests.utils.cluster import ValkeyCluster
24-
from tests.utils.utils import DEFAULT_TEST_LOG_LEVEL, NEW_PASSWORD, create_client_config
22+
from tests.utils.utils import (
23+
DEFAULT_TEST_LOG_LEVEL,
24+
NEW_PASSWORD,
25+
auth_client,
26+
config_set_new_password,
27+
create_client_config,
28+
)
2529

2630
Logger.set_logger_config(DEFAULT_TEST_LOG_LEVEL)
2731

@@ -32,7 +36,7 @@ def glide_sync_client(
3236
cluster_mode: bool,
3337
protocol: ProtocolVersion,
3438
) -> Generator[TSyncGlideClient, None, None]:
35-
"Get async socket client for tests"
39+
"Get sync socket client for tests"
3640
client = create_sync_client(request, cluster_mode, protocol=protocol)
3741
yield client
3842
sync_test_teardown(request, cluster_mode, protocol)
@@ -86,37 +90,6 @@ def create_sync_client(
8690
return SyncGlideClient.create(config)
8791

8892

89-
def sync_auth_client(client: TSyncGlideClient, password):
90-
"""
91-
Authenticates the given TGlideClient server connected.
92-
"""
93-
if isinstance(client, GlideClient):
94-
client.custom_command(["AUTH", password])
95-
elif isinstance(client, GlideClusterClient):
96-
client.custom_command(["AUTH", password], route=AllNodes())
97-
98-
99-
def sync_config_set_new_password(client: TSyncGlideClient, password):
100-
"""
101-
Sets a new password for the given TGlideClient server connected.
102-
This function updates the server to require a new password.
103-
"""
104-
if isinstance(client, GlideClient):
105-
client.config_set({"requirepass": password})
106-
elif isinstance(client, GlideClusterClient):
107-
client.config_set({"requirepass": password}, route=AllNodes())
108-
109-
110-
def sync_kill_connections(client: TSyncGlideClient):
111-
"""
112-
Kills all connections to the given TGlideClient server connected.
113-
"""
114-
if isinstance(client, GlideClient):
115-
client.custom_command(["CLIENT", "KILL", "TYPE", "normal"])
116-
elif isinstance(client, GlideClusterClient):
117-
client.custom_command(["CLIENT", "KILL", "TYPE", "normal"], route=AllNodes())
118-
119-
12093
def sync_test_teardown(request, cluster_mode: bool, protocol: ProtocolVersion):
12194
"""
12295
Perform teardown tasks such as flushing all data from the cluster.
@@ -145,9 +118,9 @@ def sync_test_teardown(request, cluster_mode: bool, protocol: ProtocolVersion):
145118
credentials=credentials,
146119
)
147120
try:
148-
sync_auth_client(client, NEW_PASSWORD)
121+
auth_client(client, NEW_PASSWORD)
149122
# Reset the server password back to empty
150-
sync_config_set_new_password(client, "")
123+
config_set_new_password(client, "")
151124
client.update_connection_password(None)
152125
# Perform the teardown
153126
client.custom_command(["FLUSHALL"])

python/tests/sync_tests/test_sync_client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
SlotType,
8282
)
8383
from glide.sync.glide_client import GlideClient, GlideClusterClient, TGlideClient
84-
8584
from tests.sync_tests.conftest import create_sync_client
8685
from tests.utils.utils import (
8786
check_function_list_response,

python/tests/test_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
22

33
from glide.logger import Level, Logger
4-
54
from tests.utils.utils import DEFAULT_TEST_LOG_LEVEL, compare_maps
65

76

python/tests/utils/utils.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@
3939
from glide.glide_client import GlideClient, GlideClusterClient, TGlideClient
4040
from glide.logger import Level as logLevel
4141
from glide.routes import AllNodes
42+
from glide.sync import GlideClient as SyncGlideClient
43+
from glide.sync import GlideClusterClient as SyncGlideClusterClient
4244
from glide.sync import TGlideClient as TSyncGlideClient
4345

46+
TAnyGlideClient = Union[TGlideClient, TSyncGlideClient]
47+
4448
from tests.utils.cluster import ValkeyCluster
4549

4650
T = TypeVar("T")
@@ -447,6 +451,7 @@ async def delete_acl_username_and_password(client: TGlideClient, username: str):
447451
["ACL", "DELUSER", username], route=AllNodes()
448452
)
449453

454+
450455
def create_client_config(
451456
request,
452457
cluster_mode: bool,
@@ -510,6 +515,7 @@ def create_client_config(
510515
)
511516
return config
512517

518+
513519
def run_sync_func_with_timeout_in_thread(
514520
func: Callable, timeout: float, on_timeout=None
515521
):
@@ -534,3 +540,42 @@ def run_sync_func_with_timeout_in_thread(
534540
finally:
535541
# Shutdown with cancel_futures=True to prevent hanging
536542
executor.shutdown(wait=False, cancel_futures=True)
543+
544+
545+
def auth_client(client: TAnyGlideClient, password: str, username: str = "default"):
546+
"""
547+
Authenticates the given TGlideClient server connected.
548+
When passing a sync client, this returns the result of the AUTH command.
549+
When passing an async client, this returns a coroutine that should be awaited.
550+
"""
551+
if isinstance(client, (GlideClient, SyncGlideClient)):
552+
return client.custom_command(["AUTH", username, password])
553+
elif isinstance(client, (GlideClusterClient, SyncGlideClusterClient)):
554+
return client.custom_command(["AUTH", username, password], route=AllNodes())
555+
556+
557+
def config_set_new_password(client: TAnyGlideClient, password):
558+
"""
559+
Sets a new password for the given TGlideClient server connected.
560+
This function updates the server to require a new password.
561+
When passing a sync client, this returns the reuslt of the CONFIG SET command.
562+
When passing an async client, this returns a coroutine that should be awaited.
563+
"""
564+
if isinstance(client, (GlideClient, SyncGlideClient)):
565+
return client.config_set({"requirepass": password})
566+
elif isinstance(client, (GlideClusterClient, SyncGlideClusterClient)):
567+
return client.config_set({"requirepass": password}, route=AllNodes())
568+
569+
570+
def kill_connections(client: TAnyGlideClient):
571+
"""
572+
Kills all connections to the given TGlideClient server connected.
573+
When passing a sync client, this returns the reuslt of the CLIENT KILL command.
574+
When passing an async client, this returns a coroutine that should be awaited.
575+
"""
576+
if isinstance(client, (GlideClient, SyncGlideClient)):
577+
return client.custom_command(["CLIENT", "KILL", "TYPE", "normal"])
578+
elif isinstance(client, (GlideClusterClient, SyncGlideClusterClient)):
579+
return client.custom_command(
580+
["CLIENT", "KILL", "TYPE", "normal"], route=AllNodes()
581+
)

0 commit comments

Comments
 (0)