Skip to content

Commit 2150e1f

Browse files
authored
pytest: Retry set until failure after ACL update (#5823)
pytest: Retry set until failure In test_acl_cat_commands_multi_exec_squash we set an ACL to deny set commands, and then check if subsequent set command fails. However this can fail because of time taken for the ACL setuser to propagate changes to shards, during this time a set command may succeed. The test is changed to retry the command a fixed number of times until eventually it is denied. Signed-off-by: Abhijat Malviya <[email protected]>
1 parent 3e35461 commit 2150e1f

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

tests/dragonfly/acl_family_test.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
import pytest
2-
import redis
3-
from redis import asyncio as aioredis
4-
from .instance import DflyInstanceFactory
5-
from .utility import *
61
import tempfile
7-
import asyncio
8-
import os
9-
from . import dfly_args
2+
103
import async_timeout
114

5+
from . import dfly_args
6+
from .utility import *
7+
128

139
@pytest.mark.asyncio
1410
async def test_acl_setuser(async_client):
@@ -141,7 +137,6 @@ async def test_acl_commands(async_client):
141137
await async_client.execute_command("ZADD myset 1 two")
142138

143139

144-
@pytest.mark.exclude_epoll # Failing test. It should be turned on as soon as it is fixed.
145140
@pytest.mark.asyncio
146141
async def test_acl_cat_commands_multi_exec_squash(df_factory):
147142
df = df_factory.create(multi_exec_squash=True, port=1111)
@@ -234,8 +229,18 @@ async def test_acl_cat_commands_multi_exec_squash(df_factory):
234229
# NOPERM while executing multi
235230
await client.execute_command("MULTI")
236231

237-
with pytest.raises(redis.exceptions.NoPermissionError):
238-
await client.execute_command(f"SET x{x} {x}")
232+
# retry for a few seconds while the ACL SETUSER propagates, some SET commands might get through
233+
start = time.time()
234+
denied = False
235+
while not denied and time.time() - start < 10:
236+
try:
237+
await client.execute_command(f"SET x{x} {x}")
238+
asyncio.sleep(0.1)
239+
except redis.exceptions.NoPermissionError:
240+
denied = True
241+
except Exception as e:
242+
assert False, f"failed with unexpected error: {e}"
243+
assert denied, "all SET commands succeeded unexpectedly defying ACL"
239244

240245

241246
@pytest.mark.asyncio

0 commit comments

Comments
 (0)