Skip to content

Commit

Permalink
chore: run tests with list_experimental_v2 enabled (#4112)
Browse files Browse the repository at this point in the history
Also fix issues with memory_test.py running locally.

Signed-off-by: Roman Gershman <[email protected]>
  • Loading branch information
romange authored Nov 15, 2024
1 parent 2ff6bf3 commit 8e3b8cc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
6 changes: 5 additions & 1 deletion tests/dragonfly/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def cluster_client(self, *args, **kwargs) -> RedisCluster:

async def close_clients(self):
for client in self.clients:
await client.close()
await client.aclose() if hasattr(client, "aclose") else client.close()

def __enter__(self):
self.start()
Expand Down Expand Up @@ -411,6 +411,10 @@ def create(self, existing_port=None, path=None, version=100, **kwargs) -> DflyIn
vmod = "dragonfly_connection=1,accept_server=1,listener_interface=1,main_service=1,rdb_save=1,replica=1,cluster_family=1,proactor_pool=1,dflycmd=1"
args.setdefault("vmodule", vmod)
args.setdefault("jsonpathv2")

# If path is not set, we assume that we are running the latest dragonfly.
if not path:
args.setdefault("list_experimental_v2")
args.setdefault("log_dir", self.params.log_dir)

if version >= 1.21:
Expand Down
23 changes: 11 additions & 12 deletions tests/dragonfly/memory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .utility import *
import logging
from . import dfly_args
from .instance import DflyInstance, DflyInstanceFactory


@pytest.mark.opt_only
Expand All @@ -17,17 +18,16 @@
("STRING", 3_500_000, 1000, 1),
],
)
async def test_rss_used_mem_gap(df_factory, type, keys, val_size, elements):
# We limit to 5gb just in case to sanity check the gh runner. Otherwise, if we ask for too much
# memory it might force the gh runner to run out of memory (since OOM killer might not even
# get a chance to run).
@dfly_args({"proactor_threads": 4, "maxmemory": "5gb"})
async def test_rss_used_mem_gap(df_server: DflyInstance, type, keys, val_size, elements):
# Create a Dragonfly and fill it up with `type` until it reaches `min_rss`, then make sure that
# the gap between used_memory and rss is no more than `max_unaccounted_ratio`.
min_rss = 3 * 1024 * 1024 * 1024 # 3gb
max_unaccounted = 200 * 1024 * 1024 # 200mb

# We limit to 5gb just in case to sanity check the gh runner. Otherwise, if we ask for too much
# memory it might force the gh runner to run out of memory (since OOM killer might not even
# get a chance to run).
df_server = df_factory.create(maxmemory="5gb")
df_factory.start_all([df_server])
client = df_server.client()
await asyncio.sleep(1) # Wait for another RSS heartbeat update in Dragonfly

Expand Down Expand Up @@ -60,21 +60,20 @@ async def test_rss_used_mem_gap(df_factory, type, keys, val_size, elements):
}
)
@pytest.mark.parametrize("admin_port", [0, 1112])
async def test_rss_oom_ratio(df_factory, admin_port):
async def test_rss_oom_ratio(df_factory: DflyInstanceFactory, admin_port):
"""
Test dragonfly rejects denyoom commands and new connections when rss memory is above maxmemory*rss_oom_deny_ratio
Test dragonfly does not rejects when rss memory goes below threshold
"""
df_server = df_factory.create(admin_port=admin_port)
df_server.start()

client = aioredis.Redis(port=df_server.port)
client = df_server.client()
await client.execute_command("DEBUG POPULATE 10000 key 40000 RAND")

await asyncio.sleep(1) # Wait for another RSS heartbeat update in Dragonfly

port = df_server.admin_port if admin_port else df_server.port
new_client = aioredis.Redis(port=port)
new_client = df_server.admin_client() if admin_port else df_server.client()
await new_client.ping()

info = await new_client.info("memory")
Expand All @@ -92,7 +91,7 @@ async def test_rss_oom_ratio(df_factory, admin_port):

if admin_port:
# new client create should also fail if admin port was set
client = aioredis.Redis(port=df_server.port)
client = df_server.client()
with pytest.raises(redis.exceptions.ConnectionError):
await client.ping()

Expand All @@ -106,5 +105,5 @@ async def test_rss_oom_ratio(df_factory, admin_port):
assert info["used_memory_rss"] < reject_limit

# new client create shoud not fail after memory usage decrease
client = aioredis.Redis(port=df_server.port)
client = df_server.client()
await client.execute_command("set x y")

0 comments on commit 8e3b8cc

Please sign in to comment.