Skip to content

Commit

Permalink
Add modules testing CI (#2162)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: Shoham Elias <shohame@amazon.com>
  • Loading branch information
shohamazon authored Aug 20, 2024
1 parent 302a79c commit 866d47a
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 23 deletions.
79 changes: 78 additions & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ on:
- .github/workflows/install-valkey/action.yml
- .github/json_matrices/build-matrix.json
- .github/json_matrices/engine-matrix.json
- .github/workflows/start-self-hosted-runner/action.yml

pull_request:
paths:
Expand All @@ -31,6 +32,7 @@ on:
- .github/workflows/install-valkey/action.yml
- .github/json_matrices/build-matrix.json
- .github/json_matrices/engine-matrix.json
- .github/workflows/start-self-hosted-runner/action.yml
workflow_dispatch:

concurrency:
Expand All @@ -39,6 +41,8 @@ concurrency:

permissions:
contents: read
# Allows the GITHUB_TOKEN to make an API call to generate an OIDC token.
id-token: write

jobs:
load-engine-matrix:
Expand Down Expand Up @@ -156,7 +160,7 @@ jobs:
OS: ubuntu,
RUNNER: ubuntu-latest,
TARGET: x86_64-unknown-linux-gnu
}
}
# - {
# OS: macos,
# RUNNER: macos-latest,
Expand Down Expand Up @@ -284,3 +288,76 @@ jobs:
name: smoke-test-report-amazon-linux
path: |
python/python/tests/pytest_report.html
start-self-hosted-runner:
if: github.event.pull_request.head.repo.owner.login == 'valkey-io'
runs-on: ubuntu-latest
environment: AWS_ACTIONS
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Start self hosted EC2 runner
uses: ./.github/workflows/start-self-hosted-runner
with:
role-to-assume: ${{ secrets.ROLE_TO_ASSUME }}
aws-region: ${{ secrets.AWS_REGION }}
ec2-instance-id: ${{ secrets.AWS_EC2_INSTANCE_ID }}

test-modules:
needs: [start-self-hosted-runner, load-engine-matrix]
name: Running Module Tests
runs-on: ${{ matrix.host.RUNNER }}
timeout-minutes: 35
strategy:
fail-fast: false
matrix:
engine: ${{ fromJson(needs.load-engine-matrix.outputs.matrix) }}
python:
- "3.12"
host:
- {
OS: "ubuntu",
NAMED_OS: "linux",
RUNNER: ["self-hosted", "Linux", "ARM64"],
TARGET: "aarch64-unknown-linux-gnu",
}

steps:
- name: Setup self-hosted runner access
if: ${{ contains(matrix.host.RUNNER, 'self-hosted') }}
run: sudo chown -R $USER:$USER /home/ubuntu/actions-runner/_work/valkey-glide

- uses: actions/checkout@v4
with:
submodules: recursive

- name: Setup Python for self-hosted Ubuntu runners
run: |
sudo apt update -y
sudo apt upgrade -y
sudo apt install python3 python3-venv python3-pip -y
- name: Build Python wrapper
uses: ./.github/workflows/build-python-wrapper
with:
os: ${{ matrix.host.OS }}
target: ${{ matrix.host.TARGET }}
github-token: ${{ secrets.GITHUB_TOKEN }}
engine-version: ${{ matrix.engine.version }}

- name: Test with pytest
working-directory: ./python
run: |
source .env/bin/activate
cd python/tests/
pytest --asyncio-mode=auto --tls --cluster-endpoints=${{ secrets.MEMDB_MODULES_ENDPOINT }} -k server_modules --html=pytest_report.html --self-contained-html
- name: Upload test reports
if: always()
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: smoke-test-report-amazon-linux
path: |
python/python/tests/pytest_report.html
36 changes: 14 additions & 22 deletions python/python/tests/tests_server_modules/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@

@pytest.mark.asyncio
class TestJson:
@pytest.mark.parametrize("cluster_mode", [True, False])
@pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3])
async def test_json_module_is_loaded(self, glide_client: TGlideClient):
res = parse_info_response(await glide_client.info([InfoSection.MODULES]))
assert "ReJSON" in res["module"]

@pytest.mark.parametrize("cluster_mode", [True, False])
@pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3])
async def test_json_set_get(self, glide_client: TGlideClient):
Expand All @@ -30,15 +24,15 @@ async def test_json_set_get(self, glide_client: TGlideClient):
assert await json.set(glide_client, key, "$", OuterJson.dumps(json_value)) == OK

result = await json.get(glide_client, key, ".")
assert isinstance(result, str)
assert isinstance(result, bytes)
assert OuterJson.loads(result) == json_value

result = await json.get(glide_client, key, ["$.a", "$.b"])
assert isinstance(result, str)
assert isinstance(result, bytes)
assert OuterJson.loads(result) == {"$.a": [1.0], "$.b": [2]}

assert await json.get(glide_client, "non_existing_key", "$") is None
assert await json.get(glide_client, key, "$.d") == "[]"
assert await json.get(glide_client, key, "$.d") == b"[]"

@pytest.mark.parametrize("cluster_mode", [True, False])
@pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3])
Expand All @@ -56,16 +50,16 @@ async def test_json_set_get_multiple_values(self, glide_client: TGlideClient):
)

result = await json.get(glide_client, key, "$..c")
assert isinstance(result, str)
assert isinstance(result, bytes)
assert OuterJson.loads(result) == [True, 1, 2]

result = await json.get(glide_client, key, ["$..c", "$.c"])
assert isinstance(result, str)
assert isinstance(result, bytes)
assert OuterJson.loads(result) == {"$..c": [True, 1, 2], "$.c": [True]}

assert await json.set(glide_client, key, "$..c", '"new_value"') == OK
result = await json.get(glide_client, key, "$..c")
assert isinstance(result, str)
assert isinstance(result, bytes)
assert OuterJson.loads(result) == ["new_value"] * 3

@pytest.mark.parametrize("cluster_mode", [True, False])
Expand Down Expand Up @@ -105,7 +99,7 @@ async def test_json_set_conditional_set(self, glide_client: TGlideClient):
is None
)

assert await json.get(glide_client, key, ".a") == "1.0"
assert await json.get(glide_client, key, ".a") == b"1.0"

assert (
await json.set(
Expand All @@ -118,7 +112,7 @@ async def test_json_set_conditional_set(self, glide_client: TGlideClient):
== OK
)

assert await json.get(glide_client, key, ".a") == "4.5"
assert await json.get(glide_client, key, ".a") == b"4.5"

@pytest.mark.parametrize("cluster_mode", [True, False])
@pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3])
Expand All @@ -138,16 +132,14 @@ async def test_json_get_formatting(self, glide_client: TGlideClient):
glide_client, key, "$", JsonGetOptions(indent=" ", newline="\n", space=" ")
)

expected_result = '[\n {\n "a": 1.0,\n "b": 2,\n "c": {\n "d": 3,\n "e": 4\n }\n }\n]'
expected_result = b'[\n {\n "a": 1.0,\n "b": 2,\n "c": {\n "d": 3,\n "e": 4\n }\n }\n]'
assert result == expected_result

result = await json.get(
glide_client, key, "$", JsonGetOptions(indent="~", newline="\n", space="*")
)

expected_result = (
'[\n~{\n~~"a":*1.0,\n~~"b":*2,\n~~"c":*{\n~~~"d":*3,\n~~~"e":*4\n~~}\n~}\n]'
)
expected_result = b'[\n~{\n~~"a":*1.0,\n~~"b":*2,\n~~"c":*{\n~~~"d":*3,\n~~~"e":*4\n~~}\n~}\n]'
assert result == expected_result

@pytest.mark.parametrize("cluster_mode", [True, False])
Expand All @@ -159,10 +151,10 @@ async def test_del(self, glide_client: TGlideClient):
assert await json.set(glide_client, key, "$", OuterJson.dumps(json_value)) == OK

assert await json.delete(glide_client, key, "$..a") == 2
assert await json.get(glide_client, key, "$..a") == "[]"
assert await json.get(glide_client, key, "$..a") == b"[]"

result = await json.get(glide_client, key, "$")
assert isinstance(result, str)
assert isinstance(result, bytes)
assert OuterJson.loads(result) == [{"b": {"b": 2.5, "c": True}}]

assert await json.delete(glide_client, key, "$") == 1
Expand All @@ -178,10 +170,10 @@ async def test_forget(self, glide_client: TGlideClient):
assert await json.set(glide_client, key, "$", OuterJson.dumps(json_value)) == OK

assert await json.forget(glide_client, key, "$..a") == 2
assert await json.get(glide_client, key, "$..a") == "[]"
assert await json.get(glide_client, key, "$..a") == b"[]"

result = await json.get(glide_client, key, "$")
assert isinstance(result, str)
assert isinstance(result, bytes)
assert OuterJson.loads(result) == [{"b": {"b": 2.5, "c": True}}]

assert await json.forget(glide_client, key, "$") == 1
Expand Down

0 comments on commit 866d47a

Please sign in to comment.