1+ import requests
12import random
23import logging
34import string
2324from . import dfly_args
2425from .instance import DflyInstance , DflyInstanceFactory
2526
27+ from prometheus_client .parser import text_string_to_metric_families
28+
2629BASE_PORT = 1111
2730
2831
@@ -610,18 +613,29 @@ async def test_keyspace_events_config_set(async_client: aioredis.Redis):
610613async def test_reply_count (async_client : aioredis .Redis ):
611614 """Make sure reply aggregations reduce reply counts for common cases"""
612615
613- async def get_reply_count ():
614- return (await async_client .info ("STATS" ))["reply_count" ]
616+ port = int (async_client .get_connection_kwargs ().get ("port" ))
617+ METRICS_URL = f"http://localhost:{ port } /metrics"
618+ logging .getLogger ("urllib3" ).setLevel (logging .WARNING )
619+
620+ def get_reply_count ():
621+ response = requests .get (METRICS_URL )
622+ response .raise_for_status ()
623+ families = text_string_to_metric_families (response .text )
624+ for metric in families :
625+ if metric .name == "dragonfly_reply" :
626+ assert metric .type == "counter"
627+ return int (metric .samples [0 ].value )
628+ return None
615629
616630 async def measure (aw ):
617- before = await get_reply_count ()
631+ before = get_reply_count ()
618632 await aw
619- return await get_reply_count () - before - 1
633+ return get_reply_count () - before
620634
621635 await async_client .config_resetstat ()
622- base = await get_reply_count ()
623- info_diff = await get_reply_count () - base
624- assert info_diff == 1
636+ base = get_reply_count ()
637+ info_diff = get_reply_count () - base
638+ assert info_diff == 0 # no commands yet
625639
626640 # Warm client buffer up
627641 await async_client .lpush ("warmup" , * (i for i in range (500 )))
@@ -638,21 +652,20 @@ async def measure(aw):
638652 # Sorted sets
639653 await async_client .zadd ("zset-1" , mapping = {str (i ): i for i in range (50 )})
640654 assert await measure (async_client .zrange ("zset-1" , 0 , - 1 , withscores = True )) == 1
641-
642655 # Exec call
643656 e = async_client .pipeline (transaction = True )
644657 for _ in range (100 ):
645658 e .incr ("num-1" )
646659
647660 # one - for MULTI-OK, one for the rest. Depends on the squashing efficiency,
648661 # can be either 1 or 2 replies.
649- assert await measure (e .execute ()) <= 2
662+ assert await measure (e .execute ()) <= 1
650663
651664 # Just pipeline
652665 p = async_client .pipeline (transaction = False )
653666 for _ in range (100 ):
654667 p .incr ("num-1" )
655- assert await measure (p .execute ()) <= 2
668+ assert await measure (p .execute ()) <= 1
656669
657670 # Script result
658671 assert await measure (async_client .eval ('return {1,2,{3,4},5,6,7,8,"nine"}' , 0 )) == 1
0 commit comments