mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 18:35:46 +02:00
chore: replace try assert false with pytest.raises (#4662)
Signed-off-by: kostas <kostas@dragonflydb.io>
This commit is contained in:
parent
7e47cfc5ca
commit
ebccc25795
5 changed files with 24 additions and 35 deletions
|
@ -670,11 +670,10 @@ async def test_cluster_slot_ownership_changes(df_factory: DflyInstanceFactory):
|
|||
assert (await c_nodes[0].get("KEY0")) == "value"
|
||||
|
||||
# Make sure that "KEY1" is not owned by node1
|
||||
try:
|
||||
with pytest.raises(redis.exceptions.ResponseError) as e:
|
||||
await c_nodes[1].set("KEY1", "value")
|
||||
assert False, "Should not be able to set key on non-owner cluster node"
|
||||
except redis.exceptions.ResponseError as e:
|
||||
assert e.args[0] == f"MOVED 5259 localhost:{nodes[0].port}"
|
||||
|
||||
assert e.value.args[0] == f"MOVED 5259 localhost:{nodes[0].port}"
|
||||
|
||||
# And that node1 only has 1 key ("KEY2")
|
||||
assert await c_nodes[1].execute_command("DBSIZE") == 1
|
||||
|
@ -694,11 +693,10 @@ async def test_cluster_slot_ownership_changes(df_factory: DflyInstanceFactory):
|
|||
assert await c_nodes[1].execute_command("DBSIZE") == 1
|
||||
|
||||
# Now node0 should reply with MOVED for "KEY1"
|
||||
try:
|
||||
with pytest.raises(redis.exceptions.ResponseError) as e:
|
||||
await c_nodes[0].set("KEY1", "value")
|
||||
assert False, "Should not be able to set key on non-owner cluster node"
|
||||
except redis.exceptions.ResponseError as e:
|
||||
assert e.args[0] == f"MOVED 5259 localhost:{nodes[1].port}"
|
||||
|
||||
assert e.value.args[0] == f"MOVED 5259 localhost:{nodes[1].port}"
|
||||
|
||||
# And node1 should own it and allow using it
|
||||
assert await c_nodes[1].set("KEY1", "value")
|
||||
|
@ -826,11 +824,11 @@ async def test_cluster_replica_sets_non_owned_keys(df_factory: DflyInstanceFacto
|
|||
assert await c_replica.execute_command("dbsize") == 2
|
||||
|
||||
# The replica should still reply with MOVED, despite having that key.
|
||||
try:
|
||||
with pytest.raises(redis.exceptions.ResponseError) as e:
|
||||
await c_replica.get("key2")
|
||||
assert False, "Should not be able to get key on non-owner cluster node"
|
||||
except redis.exceptions.ResponseError as e:
|
||||
assert re.match(r"MOVED \d+ localhost:1111", e.args[0])
|
||||
|
||||
assert re.match(r"MOVED \d+ localhost:1111", e.value.args[0])
|
||||
|
||||
await push_config(replica_config, [c_master_admin])
|
||||
await asyncio.sleep(0.5)
|
||||
|
|
|
@ -13,7 +13,7 @@ import redis as base_redis
|
|||
import hiredis
|
||||
from redis.cache import CacheConfig
|
||||
|
||||
from redis.exceptions import ConnectionError as redis_conn_error, ResponseError
|
||||
from redis.exceptions import ConnectionError, ResponseError
|
||||
|
||||
import async_timeout
|
||||
from dataclasses import dataclass
|
||||
|
@ -505,7 +505,7 @@ async def test_keyspace_events(async_client: aioredis.Redis):
|
|||
|
||||
async def test_keyspace_events_config_set(async_client: aioredis.Redis):
|
||||
# nonsense does not make sense as argument, we only accept ex or empty string
|
||||
with pytest.raises((ResponseError)):
|
||||
with pytest.raises(ResponseError):
|
||||
await async_client.config_set("notify_keyspace_events", "nonsense")
|
||||
|
||||
await async_client.config_set("notify_keyspace_events", "ex")
|
||||
|
@ -520,12 +520,9 @@ async def test_keyspace_events_config_set(async_client: aioredis.Redis):
|
|||
|
||||
keys = await produce_expiring_keys(async_client)
|
||||
await async_client.config_set("notify_keyspace_events", "")
|
||||
try:
|
||||
with pytest.raises(asyncio.TimeoutError):
|
||||
async with async_timeout.timeout(1):
|
||||
await collect_expiring_events(pclient, keys)
|
||||
assert False
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.exclude_epoll
|
||||
|
@ -787,7 +784,7 @@ async def test_reject_non_tls_connections_on_tls(with_tls_server_args, df_factor
|
|||
server.start()
|
||||
|
||||
client = server.client(password="XXX")
|
||||
with pytest.raises((ResponseError)):
|
||||
with pytest.raises(ResponseError):
|
||||
await client.dbsize()
|
||||
await client.aclose()
|
||||
|
||||
|
@ -822,7 +819,7 @@ async def test_tls_reject(
|
|||
await client.aclose()
|
||||
|
||||
client = server.client(**with_tls_client_args)
|
||||
with pytest.raises(redis_conn_error):
|
||||
with pytest.raises(ConnectionError):
|
||||
await client.ping()
|
||||
|
||||
|
||||
|
|
|
@ -36,11 +36,10 @@ async def test_access_json_value_as_string(async_client: aioredis.Redis):
|
|||
the_type = await async_client.type(key_name)
|
||||
assert the_type == "ReJSON-RL"
|
||||
# you cannot access this key as string
|
||||
try:
|
||||
with pytest.raises(redis.exceptions.ResponseError) as e:
|
||||
result = await async_client.get(key_name)
|
||||
assert False, "should not be able to access JSON value as string"
|
||||
except redis.exceptions.ResponseError as e:
|
||||
assert e.args[0] == "WRONGTYPE Operation against a key holding the wrong kind of value"
|
||||
|
||||
assert e.value.args[0] == "WRONGTYPE Operation against a key holding the wrong kind of value"
|
||||
|
||||
|
||||
async def test_reset_key_to_string(async_client: aioredis.Redis):
|
||||
|
@ -78,11 +77,10 @@ async def test_update_value(async_client: aioredis.Redis):
|
|||
# Ensure that after we're changing this into STRING type, it will no longer work
|
||||
await async_client.set(key_name, "some random value")
|
||||
assert await async_client.type(key_name) == "string"
|
||||
try:
|
||||
with pytest.raises(redis.exceptions.ResponseError) as e:
|
||||
await get_set_json(async_client, value="0", key=key_name, path="$.a.*")
|
||||
assert False, "should not be able to modify JSON value as string"
|
||||
except redis.exceptions.ResponseError as e:
|
||||
assert e.args[0] == "WRONGTYPE Operation against a key holding the wrong kind of value"
|
||||
|
||||
assert e.value.args[0] == "WRONGTYPE Operation against a key holding the wrong kind of value"
|
||||
assert await async_client.type(key_name) == "string"
|
||||
|
||||
|
||||
|
|
|
@ -1176,11 +1176,10 @@ async def test_readonly_script(df_factory):
|
|||
|
||||
await c_replica.eval(READONLY_SCRIPT, 3, "A", "B", "WORKS") == "YES"
|
||||
|
||||
try:
|
||||
with pytest.raises(aioredis.ResponseError) as roe:
|
||||
await c_replica.eval(WRITE_SCRIPT, 1, "A")
|
||||
assert False
|
||||
except aioredis.ResponseError as roe:
|
||||
assert "READONLY " in str(roe)
|
||||
|
||||
assert "READONLY " in str(roe)
|
||||
|
||||
|
||||
take_over_cases = [
|
||||
|
|
|
@ -296,11 +296,8 @@ async def test_path_escapes(df_factory):
|
|||
fails because we don't have a much better way to test that."""
|
||||
|
||||
df_server = df_factory.create(dbfilename="../../../../etc/passwd")
|
||||
try:
|
||||
with pytest.raises(Exception):
|
||||
df_server.start()
|
||||
assert False, "Server should not start correctly"
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
|
||||
@dfly_args({**BASIC_ARGS, "dbfilename": "test-info-persistence"})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue