Skip to content
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

Fixes for valkey 8.0 #124

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,11 @@ def master_host(request):
return parts.hostname, (parts.port or 6379)


@pytest.fixture()
def valkey_version():
return Version(VALKEY_INFO["version"])


def wait_for_command(client, monitor, command, key=None):
# issue a command with a key name that's local to this process.
# if we find a command with our key before the command we're waiting
Expand Down
14 changes: 10 additions & 4 deletions tests/test_asyncio/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import pytest
import pytest_asyncio
import valkey
from packaging.version import Version
from tests.conftest import (
assert_geo_is_close,
assert_resp_response,
Expand Down Expand Up @@ -2378,13 +2379,18 @@ async def test_readwrite(self, r: valkey.Valkey):

@skip_if_server_version_lt("3.0.0")
@pytest.mark.onlynoncluster
async def test_readonly_invalid_cluster_state(self, r: valkey.Valkey):
with pytest.raises(exceptions.ValkeyError):
await r.readonly()
async def test_readonly(self, r: valkey.Valkey, valkey_version: Version):
# NOTE: Valkey 8.0.0 changes the behaviour of READONLY
# See https://github.com/valkey-io/valkey/pull/325
if valkey_version < Version("8.0.0"):
with pytest.raises(exceptions.ValkeyError):
await r.readonly()
else:
assert await r.readonly() is True

@skip_if_server_version_lt("3.0.0")
@pytest.mark.onlynoncluster
async def test_readonly(self, mock_cluster_resp_ok):
async def test_mock_readonly(self, mock_cluster_resp_ok):
assert await mock_cluster_resp_ok.readonly() is True

# GEO COMMANDS
Expand Down
3 changes: 3 additions & 0 deletions tests/test_asyncio/test_hash.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import asyncio
from datetime import datetime, timedelta

import pytest
from tests.conftest import skip_if_server_version_lt

pytestmark = pytest.mark.skip


@skip_if_server_version_lt("7.3.240")
async def test_hexpire_basic(r):
Expand Down
24 changes: 17 additions & 7 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import pytest
import valkey
from packaging.version import Version
from valkey import exceptions
from valkey._parsers.helpers import (
_ValkeyCallbacks,
Expand Down Expand Up @@ -698,11 +699,15 @@ def test_client_kill_filter_by_user(self, r, request):
@skip_if_server_version_lt("7.3.240")
@pytest.mark.onlynoncluster
def test_client_kill_filter_by_maxage(self, r, request):
_get_client(valkey.Valkey, request, flushdb=False)
client = _get_client(valkey.Valkey, request, flushdb=False)
client_name = "test-kill-by-maxage"
client.client_setname(client_name)
time.sleep(4)
assert len(r.client_list()) >= 2
clients = r.client_list()
assert client_name in [c["name"] for c in clients]
r.client_kill_filter(maxage=2)
assert len(r.client_list()) == 1
clients = r.client_list()
assert client_name not in [c["name"] for c in clients]

@pytest.mark.onlynoncluster
@skip_if_server_version_lt("2.9.50")
Expand Down Expand Up @@ -3425,13 +3430,18 @@ def test_readwrite(self, r):

@pytest.mark.onlynoncluster
@skip_if_server_version_lt("3.0.0")
def test_readonly_invalid_cluster_state(self, r):
with pytest.raises(exceptions.ValkeyError):
r.readonly()
def test_readonly(self, r, valkey_version):
# NOTE: Valkey 8.0.0 changes the behaviour of READONLY
# See https://github.com/valkey-io/valkey/pull/325
if valkey_version < Version("8.0.0"):
with pytest.raises(exceptions.ValkeyError):
r.readonly()
else:
assert r.readonly() is True

@pytest.mark.onlynoncluster
@skip_if_server_version_lt("3.0.0")
def test_readonly(self, mock_cluster_resp_ok):
def test_readonly_mock(self, mock_cluster_resp_ok):
assert mock_cluster_resp_ok.readonly() is True

# GEO COMMANDS
Expand Down
2 changes: 2 additions & 0 deletions tests/test_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import pytest
from tests.conftest import skip_if_server_version_lt

pytestmark = pytest.mark.skip


@skip_if_server_version_lt("7.3.240")
def test_hexpire_basic(r):
Expand Down
Loading