Skip to content

Commit e456432

Browse files
author
Mikhail Koviazin
committed
tests: take into account changed behaviour of READONLY
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>
1 parent 3f6a575 commit e456432

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,11 @@ def master_host(request):
456456
return parts.hostname, (parts.port or 6379)
457457

458458

459+
@pytest.fixture()
460+
def valkey_version():
461+
return Version(VALKEY_INFO["version"])
462+
463+
459464
def wait_for_command(client, monitor, command, key=None):
460465
# issue a command with a key name that's local to this process.
461466
# if we find a command with our key before the command we're waiting

tests/test_asyncio/test_commands.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import pytest
1515
import pytest_asyncio
1616
import valkey
17+
from packaging.version import Version
1718
from tests.conftest import (
1819
assert_geo_is_close,
1920
assert_resp_response,
@@ -2378,13 +2379,18 @@ async def test_readwrite(self, r: valkey.Valkey):
23782379

23792380
@skip_if_server_version_lt("3.0.0")
23802381
@pytest.mark.onlynoncluster
2381-
async def test_readonly_invalid_cluster_state(self, r: valkey.Valkey):
2382-
with pytest.raises(exceptions.ValkeyError):
2383-
await r.readonly()
2382+
async def test_readonly(self, r: valkey.Valkey, valkey_version: Version):
2383+
# NOTE: Valkey 8.0.0 changes the behaviour of READONLY
2384+
# See https://github.com/valkey-io/valkey/pull/325
2385+
if valkey_version < Version("8.0.0"):
2386+
with pytest.raises(exceptions.ValkeyError):
2387+
await r.readonly()
2388+
else:
2389+
assert await r.readonly() is True
23842390

23852391
@skip_if_server_version_lt("3.0.0")
23862392
@pytest.mark.onlynoncluster
2387-
async def test_readonly(self, mock_cluster_resp_ok):
2393+
async def test_mock_readonly(self, mock_cluster_resp_ok):
23882394
assert await mock_cluster_resp_ok.readonly() is True
23892395

23902396
# GEO COMMANDS

tests/test_commands.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import pytest
1313
import valkey
14+
from packaging.version import Version
1415
from valkey import exceptions
1516
from valkey._parsers.helpers import (
1617
_ValkeyCallbacks,
@@ -3425,13 +3426,18 @@ def test_readwrite(self, r):
34253426

34263427
@pytest.mark.onlynoncluster
34273428
@skip_if_server_version_lt("3.0.0")
3428-
def test_readonly_invalid_cluster_state(self, r):
3429-
with pytest.raises(exceptions.ValkeyError):
3430-
r.readonly()
3429+
def test_readonly(self, r, valkey_version):
3430+
# NOTE: Valkey 8.0.0 changes the behaviour of READONLY
3431+
# See https://github.com/valkey-io/valkey/pull/325
3432+
if valkey_version < Version("8.0.0"):
3433+
with pytest.raises(exceptions.ValkeyError):
3434+
r.readonly()
3435+
else:
3436+
assert r.readonly() is True
34313437

34323438
@pytest.mark.onlynoncluster
34333439
@skip_if_server_version_lt("3.0.0")
3434-
def test_readonly(self, mock_cluster_resp_ok):
3440+
def test_readonly_mock(self, mock_cluster_resp_ok):
34353441
assert mock_cluster_resp_ok.readonly() is True
34363442

34373443
# GEO COMMANDS

0 commit comments

Comments
 (0)