File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ # NATS server config for testing server-initiated PINGs
2+ # Set very short ping interval so server pings client quickly
3+ ping_interval: "100ms"
4+ ping_max: 3
Original file line number Diff line number Diff line change @@ -709,3 +709,28 @@ async def test_inbox_prefix_cannot_end_with_dot(server):
709709 """Test that inbox prefix ending with '.' is rejected."""
710710 with pytest .raises (ValueError , match = "inbox_prefix cannot end with '.'" ):
711711 await connect (server .client_url , inbox_prefix = "test." , timeout = 1.0 )
712+
713+
714+ @pytest .mark .asyncio
715+ async def test_server_initiated_ping_pong ():
716+ """Test that client properly handles PING from server and responds with PONG."""
717+ import os
718+
719+ # Start server with very short ping interval
720+ config_path = os .path .join (os .path .dirname (__file__ ), "configs" , "server_ping.conf" )
721+ server = await run (config_path = config_path , port = 0 , timeout = 5.0 )
722+
723+ try :
724+ client = await connect (server .client_url , timeout = 1.0 , allow_reconnect = False )
725+
726+ try :
727+ # Wait long enough for server to send at least one PING
728+ # Server is configured to ping every 100ms
729+ await asyncio .sleep (0.3 )
730+
731+ # If ping/pong handling didn't work, client would be disconnected
732+ assert client .status == ClientStatus .CONNECTED , "Client should still be connected after server PINGs"
733+ finally :
734+ await client .close ()
735+ finally :
736+ await server .shutdown ()
You can’t perform that action at this time.
0 commit comments