Skip to content

Reorganize and split tests dir and conftest files #3893

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

Merged
merged 2 commits into from
May 27, 2025

Conversation

liorsve
Copy link
Contributor

@liorsve liorsve commented May 18, 2025

Issue link

This Pull Request is linked to issue: #3634

New tests dir structure -

tests/ 
      async_tests/
             conftest.py
             ... all existing async tests
      sync_tests/
             conftest.py 
             test_sync_client.py
      conftest.py   # For shared conftest functions 

the create_client_config function and some constants were moved from the tests/conftest.py file to utils to avoid circular import problems.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one issue.
  • Commit message has a detailed description of what changed and why.
  • Tests are added or updated.
  • CHANGELOG.md and documentation files are updated.
  • Destination branch is correct - main or release
  • Create merge commit if merging release branch into main, squash otherwise.

@liorsve liorsve requested a review from a team as a code owner May 18, 2025 11:35
@liorsve liorsve added the python Python wrapper label May 18, 2025
@liorsve liorsve added this to the 2.0 milestone May 18, 2025
@liorsve liorsve force-pushed the reorganize-tests branch 2 times, most recently from ff535da to 05872bc Compare May 19, 2025 11:53
@liorsve liorsve force-pushed the reorganize-tests branch from 05872bc to 4af4d20 Compare May 25, 2025 14:20
ServerCredentials,
)
from glide.exceptions import ClosingError
from glide.glide_client import GlideClient, GlideClusterClient
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it needed? it should be separated - and only the sync client to be used here

cluster_mode: bool,
protocol: ProtocolVersion,
) -> Generator[TSyncGlideClient, None, None]:
"Get async socket client for tests"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Get async socket client for tests"
"Get sync client for tests"

return await GlideClient.create(config)


async def auth_client(client: TGlideClient, password: str, username: str = "default"):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why "username: str = "default")" isn't copied also for the sync auth_client fn?

@liorsve liorsve force-pushed the python-sync-client branch from 9cb682c to 77918d2 Compare May 26, 2025 13:34
Comment on lines 159 to 169
async def kill_connections(client: TGlideClient):
"""
Kills all connections to the given TGlideClient server connected.
"""
if isinstance(client, GlideClient):
await client.custom_command(["CLIENT", "KILL", "TYPE", "normal"])
elif isinstance(client, GlideClusterClient):
await client.custom_command(
["CLIENT", "KILL", "TYPE", "normal"], route=AllNodes()
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that one of the goals of this PR is to reduce code and logic duplication, so instead of duplicating all of these test helper functions, we can do something like the following in a shared file, changing these helpers to be blocking also for the async client (since it's only helper functions and already we call them from the tests in a blocking manner):


TGlideClient = Union[GlideClient, GlideClusterClient, GlideClientSync, GlideClusterClientSync]

def kill_connections(client: TGlideClient):
    """
    Kills all connections using .custom_command, and runs it in sync or async depending on client type.
    """
    if isinstance(client, GlideClient):
        res = client.custom_command(["CLIENT", "KILL", "TYPE", "normal"])
    elif isinstance(client, GlideClusterClient):
        res = client.custom_command(["CLIENT", "KILL", "TYPE", "normal"], route=AllNodes())
    else:
        raise TypeError("Unknown client type")

    if asyncio.iscoroutine(res):
        return asyncio.run(res)  # convert async call into sync
    return res  # sync result

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed, I added an alias
TAnyGlideClient = Union[TGlideClient, TSyncGlideClient] for this in utils.py

Copy link
Collaborator

@barshaul barshaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main comment is about merging the tests utils sync/async functions into one to reduce code and logic duplication

@liorsve liorsve force-pushed the python-sync-client branch 2 times, most recently from 122d41d to dda9443 Compare May 26, 2025 14:40
@liorsve liorsve force-pushed the reorganize-tests branch 4 times, most recently from 69984d9 to 6c62195 Compare May 27, 2025 10:41
create_client_config,
)

Logger.set_logger_config(DEFAULT_TEST_LOG_LEVEL)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can it be set only once for sync and async in the main conftest file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the logger config from the sync_tests/conftest.py file, left it in async conftest

Signed-off-by: Lior Sventitzky <[email protected]>
@liorsve liorsve force-pushed the reorganize-tests branch from 6c62195 to 558e074 Compare May 27, 2025 12:10
@liorsve liorsve merged commit 7209f71 into valkey-io:python-sync-client May 27, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Python wrapper
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants