From 358c45c2c1881abe9f0432adff46201c9c486a1c Mon Sep 17 00:00:00 2001 From: Stepan Bagritsevich Date: Fri, 22 Nov 2024 15:20:31 +0400 Subject: [PATCH] refactor: small fix Signed-off-by: Stepan Bagritsevich --- tests/dragonfly/memory_test.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/tests/dragonfly/memory_test.py b/tests/dragonfly/memory_test.py index 2ba29c40e700..85838b38bf7b 100644 --- a/tests/dragonfly/memory_test.py +++ b/tests/dragonfly/memory_test.py @@ -128,8 +128,8 @@ async def test_cache_eviction_with_rss_deny_oom( max_memory = 256 * 1024 * 1024 # 256 MB first_fill_size = int(0.25 * max_memory) # 25% of max memory - second_fill_size = int(0.3 * max_memory) # Another 35% of max memory - rss_increase_size = int(0.35 * max_memory) # 30% of max memory + second_fill_size = int(0.3 * max_memory) # Another 30% of max memory + rss_increase_size = int(0.3 * max_memory) # 30% of max memory key_size = 1024 # 1 mb num_keys_first_fill = first_fill_size // key_size @@ -143,12 +143,16 @@ async def test_cache_eviction_with_rss_deny_oom( # Get RSS memory before creating new connections info_before_connections = await async_client.info("memory") rss_before_connections = info_before_connections["used_memory_rss"] - logging.info(f"RSS after creating temporary large keys: {rss_before_connections}") + logging.info(f"RSS before creating new connections: {rss_before_connections}") - # Increase RSS memory by 35% of max memory + # tmp + evicted_keys_before_connections = info_before_connections["evicted_keys"] + logging.info(f"Evicted keys before creating new connections: {evicted_keys_before_connections}") + + # Increase RSS memory by 30% of max memory # We can simulate RSS increase by creating new connections # Estimate memory per connection - estimated_connection_memory = 10 * 1024 # 10 KB per connection + estimated_connection_memory = 15 * 1024 # 15 KB per connection num_connections = rss_increase_size // estimated_connection_memory connections = [] for _ in range(num_connections): @@ -163,6 +167,10 @@ async def test_cache_eviction_with_rss_deny_oom( rss_after_connections = info_after_connections["used_memory_rss"] logging.info(f"RSS after creating new connections: {rss_after_connections}") + # tmp + evicted_keys_after_connections = info_after_connections["evicted_keys"] + logging.info(f"Evicted keys after creating new connections: {evicted_keys_after_connections}") + assert rss_after_connections > rss_before_connections, "RSS memory should have increased." # Attempt to insert another 30% of data @@ -172,7 +180,11 @@ async def test_cache_eviction_with_rss_deny_oom( # Check that eviction has occurred info = await async_client.info("stats") - assert info.get("evicted_keys", 0) > 0, "Eviction should have occurred due to memory pressure." + rss = info["used_memory_rss"] + evicted_keys = info["evicted_keys"] + logging.info(f"RSS before creating new connections: {rss}") + logging.info(f"Evicted keys before creating new connections: {evicted_keys}") + assert evicted_keys > 0, "Eviction should have occurred due to rss memory pressure." for conn in connections: await conn.close()