Skip to content

Commit

Permalink
tests: take into account changed behaviour of READONLY
Browse files Browse the repository at this point in the history
Behaviour of READONLY was changed in
valkey-io/valkey#325 which became a part of
8.0.0. This caused test_readonly_invalid_cluster_state to fail.

This commit takes into account this change.

Signed-off-by: Mikhail Koviazin <mikhail.koviazin@aiven.io>
  • Loading branch information
mkmkme committed Nov 25, 2024
1 parent 3f6a575 commit e456432
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
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
14 changes: 10 additions & 4 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 @@ -3425,13 +3426,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

0 comments on commit e456432

Please sign in to comment.