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
Allow endpoint specification for Python and Node test #1375
Conversation
9293633
to
3b5801e
Compare
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.
Do you want us to implement similar stuff for java, C# and go?
beforeAll(async () => { | ||
cluster = await RedisCluster.createCluster(true, 3, 0); | ||
const args = process.argv.slice(2); |
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.
Can you reuse this piece of code by creating a function?
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.
why not using parseArg https://simonplend.com/command-line-argument-parsing-with-node-js-core/
python/python/tests/conftest.py
Outdated
@@ -71,8 +85,23 @@ def call_before_all_pytests(request): | |||
""" | |||
tls = request.config.getoption("--tls") | |||
load_module = request.config.getoption("--load-module") | |||
pytest.redis_cluster = RedisCluster(tls, True, load_module=load_module) | |||
pytest.standalone_cluster = RedisCluster(tls, False, 1, 1, load_module=load_module) | |||
endpoints = request.config.getoption("--cluster-endpoints") |
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.
rename to cluster_endpoints
Let's first wait for Bar's review for this pr and then decide what we should do |
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.
@shohamazon Please keep this PR only for python changes, and open the node PR only after it will be approved.
Instead of having standalone endpoints and cluster endpoints, use single endpoints option and add cluster mode flag, as we do everywhere else. Also it will require passing TLS flag
24a04cc
to
325a861
Compare
python/python/tests/conftest.py
Outdated
endpoints = request.config.getoption("--cluster-endpoints") | ||
standalone_endpoints = request.config.getoption("--standalone-endpoints") | ||
|
||
if endpoints or standalone_endpoints: |
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.
add a comment explaining the endpoints were passed by the caller, not creating clusters internally
python/python/tests/conftest.py
Outdated
pytest.redis_cluster = RedisCluster(tls=tls, addresses=endpoints) | ||
if standalone_endpoints: | ||
standalone_endpoints = [ | ||
endpoint.split(":") for endpoint in standalone_endpoints.split(",") |
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.
create an helper function parse_endpoints, and raise relevant error if the endpoints aren't parsable as they aren't in the right format
python/python/tests/conftest.py
Outdated
|
||
if endpoints or standalone_endpoints: | ||
if endpoints: | ||
endpoints = [endpoint.split(":") for endpoint in endpoints.split(",")] |
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.
here also, endpoints -> cluster_endpoints
pytest.standalone_cluster = RedisCluster( | ||
tls, addresses=standalone_endpoints | ||
) | ||
else: |
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.
add comment
// Not endpoints were provided, create new clusters
python/python/tests/conftest.py
Outdated
tls, True, load_module=load_module, addresses=endpoints | ||
) | ||
pytest.standalone_cluster = RedisCluster( | ||
tls, False, 1, 1, load_module=load_module, addresses=standalone_endpoints |
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.
please add the filed names to make it more readable
@@ -93,13 +126,37 @@ def pytest_sessionfinish(session, exitstatus): | |||
pass | |||
|
|||
|
|||
def pytest_collection_modifyitems(config, items): |
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.
add documentation what are you doing in this function
python/python/tests/conftest.py
Outdated
): | ||
if "cluster_mode" in item.fixturenames: | ||
cluster_mode_value = item.callspec.params.get("cluster_mode", None) | ||
if cluster_mode_value and not config.getoption("--cluster-endpoints"): |
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.
if cluster_mode_value is True
python/python/tests/conftest.py
Outdated
reason="Test skipped because cluster_mode=False" | ||
) | ||
) | ||
elif not cluster_mode_value and not config.getoption( |
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.
elif cluster_mode_value is False
python/python/tests/conftest.py
Outdated
if cluster_mode_value and not config.getoption("--cluster-endpoints"): | ||
item.add_marker( | ||
pytest.mark.skip( | ||
reason="Test skipped because cluster_mode=False" |
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.
.. and cluster endpoints weren't provided
python/python/tests/conftest.py
Outdated
): | ||
item.add_marker( | ||
pytest.mark.skip( | ||
reason="Test skipped because cluster_mode=True" |
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.
same
python/python/tests/conftest.py
Outdated
@pytest.fixture() | ||
async def redis_client( | ||
request, cluster_mode: bool, protocol: ProtocolVersion | ||
) -> AsyncGenerator[TRedisClient, None]: | ||
"Get async socket client for tests" | ||
client = await create_client(request, cluster_mode, protocol=protocol) | ||
yield client | ||
await flush_all_on_cluster(request, cluster_mode, protocol) |
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.
make sure to put all flush related changes in a different commit
python/python/tests/conftest.py
Outdated
parser.addoption( | ||
"--cluster-endpoints", | ||
action="store", | ||
help="Comma-separated list of cluster endpoints in the format host1:port1,host2:port2,...", |
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.
please add a note that the cluster will be flushed (both for standalone)
python/python/tests/conftest.py
Outdated
) | ||
return await RedisClient.create(config) | ||
|
||
|
||
async def flush_all_on_cluster(request, cluster_mode: bool, protocol: ProtocolVersion): |
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.
flush_all_on_cluster -> teardown
|
||
|
||
async def flush_all_on_cluster(request, cluster_mode: bool, protocol: ProtocolVersion): | ||
client = await create_client(request, cluster_mode, protocol=protocol, timeout=2000) |
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.
add a comment why are we creating a new client
@@ -259,7 +259,8 @@ async def test_can_connect_with_auth_acl( | |||
# Delete this user | |||
await redis_client.custom_command(["ACL", "DELUSER", username]) | |||
|
|||
async def test_select_standalone_database_id(self, request): | |||
@pytest.mark.parametrize("cluster_mode", [False]) | |||
async def test_select_standalone_database_id(self, request, cluster_mode): | |||
redis_client = await create_client(request, cluster_mode=False, database_id=4) |
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.
cluster_mode=False -> can be changed to cluster_mode
python/python/tests/utils/cluster.py
Outdated
@@ -65,7 +69,16 @@ def parse_cluster_script_start_output(self, output: str): | |||
nodes_list.append(NodeAddress(host, int(port))) | |||
self.nodes_addr = nodes_list | |||
|
|||
def existing_cluster(self, addresses: List[List[str]]): |
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.
existing_cluster -> init_from_existing_cluster
python/python/tests/utils/cluster.py
Outdated
self.cluster_folder = "" | ||
self.nodes_addr = [] | ||
for [host, port] in addresses: | ||
print("host, port ", host, port) |
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.
remove
python/python/tests/utils/cluster.py
Outdated
if self.cluster_folder == "": | ||
return | ||
args_list = [sys.executable, SCRIPT_FILE] | ||
if self.tls: | ||
args_list.append("--tls") |
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.
if self.cluster_folder == "": | |
return | |
args_list = [sys.executable, SCRIPT_FILE] | |
if self.tls: | |
args_list.append("--tls") | |
if self.cluster_folder: | |
args_list = [sys.executable, SCRIPT_FILE] | |
if self.tls: | |
args_list.append("--tls") |
@@ -50,12 +77,12 @@ describe("RedisClusterClient", () => { | |||
}); | |||
|
|||
const getOptions = ( | |||
ports: number[], | |||
host_port: [string, number][], |
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.
host_port -> address
node/tests/TestUtilities.ts
Outdated
@@ -40,6 +40,17 @@ export function flushallOnPort(port: number): Promise<void> { | |||
); | |||
} | |||
|
|||
export const parseEndpoints = (endpoints: string): [string, number][] => { | |||
if (!endpoints.trim()) { |
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.
why? what does this scenario mean? if endpoints is an empty string, please add appropriate check
node/tests/TestUtilities.ts
Outdated
} | ||
|
||
return endpoints.split(",").map((endpoint) => { | ||
const [host, port] = endpoint.split(":"); |
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.
handle errors and raise appropriate error if recieved format is bad
node/tests/TestUtilities.ts
Outdated
|
||
return endpoints.split(",").map((endpoint) => { | ||
const [host, port] = endpoint.split(":"); | ||
return [host, Number(port)]; |
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.
same - Number(port) can raise an error, make sure to handle those
node/tests/TestUtilities.ts
Outdated
|
||
private constructor(ports: number[], clusterFolder: string) { | ||
this.usedPorts = ports; | ||
private constructor(ports: [string, number][], clusterFolder?: string) { |
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.
rename 'ports' to 'addresses'
node/tests/TestUtilities.ts
Outdated
private constructor(ports: number[], clusterFolder: string) { | ||
this.usedPorts = ports; | ||
private constructor(ports: [string, number][], clusterFolder?: string) { | ||
this.address = ports; |
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.
can't we get multiple addresses? change to this.addresses if so
node/tests/TestUtilities.ts
Outdated
.map((address) => address.split(":")[1]) | ||
.map((port) => Number(port)); | ||
.map((address) => address.split(":")) | ||
.map((port) => [port[0], Number(port[1])]) as [string, number][]; |
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.
.map((port) => [port[0], Number(port[1])]) as [string, number][]; | |
.map((address) => [address[0], Number(address[1])]) as [string, number][]; |
node/tests/TestUtilities.ts
Outdated
@@ -295,23 +306,33 @@ export class RedisCluster { | |||
}); | |||
} | |||
|
|||
public static connectToCluster(port: [string, number][]): RedisCluster { |
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.
public static connectToCluster(port: [string, number][]): RedisCluster { | |
public static connectToCluster(address: [string, number][]): RedisCluster { |
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.
are we connecting to the cluster (e.g. creating a client), or just creating an cluster object ?
if not, change to initFromExistingCluster
node/tests/TestUtilities.ts
Outdated
}, | ||
), | ||
); | ||
if (this.clusterFolder !== "") { |
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.
if (this.clusterFolder)
isn't good enough?
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.
See comments inline
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.
fix all before merging
@@ -4,6 +4,7 @@ | |||
|
|||
import { beforeAll, expect } from "@jest/globals"; | |||
import { exec } from "child_process"; | |||
import parseArgs from "minimist"; |
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.
Please, update developer.md and/or package.json to include this module
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.
It's updated, look at the pr
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.
I see, need to update dev doc.
Issue #, if available:
Description of changes:
This PR introduces the ability to specify endpoints when running tests for both Python and Node environments.
To run the tests in python using with external endpoints:
pytest --asyncio-mode=auto --cluster-endpoints=host:port,host2:port2 --standalone-endpoints=host1:port
In Node:
npm run test -- --cluster-endpoints=host:port,host2:port2 --standalone-endpoints=host1:port
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.