@@ -35,24 +35,26 @@ class TestRealtimePresenceBasics(BaseAsyncTestCase):
3535 """Test basic presence operations: enter, leave, update."""
3636
3737 @pytest .fixture (autouse = True )
38- async def setup (self , use_binary_protocol ):
38+ async def setup (self , use_binary_protocol , request ):
3939 """Set up test fixtures."""
40- self .test_vars = await TestApp .get_test_vars ()
41- self .use_binary_protocol = use_binary_protocol
40+ test_instance = request .instance
41+
42+ test_instance .test_vars = await TestApp .get_test_vars ()
43+ test_instance .use_binary_protocol = use_binary_protocol
4244
43- self .client1 = await TestApp .get_ably_realtime (
45+ test_instance .client1 = await TestApp .get_ably_realtime (
4446 client_id = 'client1' ,
4547 use_binary_protocol = use_binary_protocol
4648 )
47- self .client2 = await TestApp .get_ably_realtime (
49+ test_instance .client2 = await TestApp .get_ably_realtime (
4850 client_id = 'client2' ,
4951 use_binary_protocol = use_binary_protocol
5052 )
5153
5254 yield
5355
54- await self .client1 .close ()
55- await self .client2 .close ()
56+ await test_instance .client1 .close ()
57+ await test_instance .client2 .close ()
5658
5759 async def test_presence_enter_without_attach (self ):
5860 """
@@ -188,24 +190,26 @@ class TestRealtimePresenceGet(BaseAsyncTestCase):
188190 """Test presence.get() functionality."""
189191
190192 @pytest .fixture (autouse = True )
191- async def setup (self , use_binary_protocol ):
193+ async def setup (self , use_binary_protocol , request ):
192194 """Set up test fixtures."""
193- self .test_vars = await TestApp .get_test_vars ()
194- self .use_binary_protocol = use_binary_protocol
195+ test_instance = request .instance
196+
197+ test_instance .test_vars = await TestApp .get_test_vars ()
198+ test_instance .use_binary_protocol = use_binary_protocol
195199
196- self .client1 = await TestApp .get_ably_realtime (
200+ test_instance .client1 = await TestApp .get_ably_realtime (
197201 client_id = 'client1' ,
198202 use_binary_protocol = use_binary_protocol
199203 )
200- self .client2 = await TestApp .get_ably_realtime (
204+ test_instance .client2 = await TestApp .get_ably_realtime (
201205 client_id = 'client2' ,
202206 use_binary_protocol = use_binary_protocol
203207 )
204208
205209 yield
206210
207- await self .client1 .close ()
208- await self .client2 .close ()
211+ await test_instance .client1 .close ()
212+ await test_instance .client2 .close ()
209213
210214 async def test_presence_enter_get (self ):
211215 """
@@ -289,36 +293,18 @@ async def setup(self, use_binary_protocol, request):
289293 test_instance .test_vars = await TestApp .get_test_vars ()
290294 test_instance .use_binary_protocol = use_binary_protocol
291295
292- protocol = 'msgpack' if use_binary_protocol else 'json'
293-
294296 test_instance .client1 = await TestApp .get_ably_realtime (
295297 client_id = 'client1' ,
296298 use_binary_protocol = use_binary_protocol
297299 )
298- print (
299- f"[{ protocol } ] FIXTURE SETUP: Created client1 id={ id (test_instance .client1 )} , "
300- f"state={ test_instance .client1 .connection .state } "
301- )
302300
303301 test_instance .client2 = await TestApp .get_ably_realtime (
304302 client_id = 'client2' ,
305303 use_binary_protocol = use_binary_protocol
306304 )
307- print (
308- f"[{ protocol } ] FIXTURE SETUP: Created client2 id={ id (test_instance .client2 )} , "
309- f"state={ test_instance .client2 .connection .state } "
310- )
311305
312306 yield
313307
314- print (
315- f"[{ protocol } ] FIXTURE TEARDOWN: client1 id={ id (test_instance .client1 )} , "
316- f"state={ test_instance .client1 .connection .state } "
317- )
318- print (
319- f"[{ protocol } ] FIXTURE TEARDOWN: client2 id={ id (test_instance .client2 )} , "
320- f"state={ test_instance .client2 .connection .state } "
321- )
322308 await test_instance .client1 .close ()
323309 await test_instance .client2 .close ()
324310
@@ -356,48 +342,49 @@ async def test_presence_message_action(self):
356342 """
357343 Test RTP8c: PresenceMessage should have correct action string.
358344 """
359- protocol = 'msgpack' if self .use_binary_protocol else 'json'
360- print (f"[{ protocol } ] TEST START: client1 id={ id (self .client1 )} , state={ self .client1 .connection .state } " )
361-
362345 channel_name = self .get_channel_name ('message_action' )
363346
364347 channel1 = self .client1 .channels .get (channel_name )
365- print (f"[{ protocol } ] TEST: Got channel, client1.state={ self .client1 .connection .state } " )
366348
367349 received = asyncio .Future ()
368350
369351 def on_presence (msg ):
370352 received .set_result (msg )
371353
372- print (f"[{ protocol } ] TEST: About to subscribe, client1.state={ self .client1 .connection .state } " )
373354 await channel1 .presence .subscribe (on_presence )
374- print (f"[{ protocol } ] TEST: About to enter, client1.state={ self .client1 .connection .state } " )
355+
356+ # Wait for channel to attach before entering to avoid race with SYNC
357+ await channel1 .attach ()
358+
375359 await channel1 .presence .enter ()
376360
377361 msg = await asyncio .wait_for (received , timeout = 5.0 )
378- assert msg .action == PresenceAction .ENTER
379- print (f"[{ protocol } ] TEST END: client1.state={ self .client1 .connection .state } " )
362+ # RTP8c: Should receive ENTER action since we're entering for the first time
363+ assert msg .action == PresenceAction .ENTER , \
364+ f"Expected ENTER action, got { msg .action } "
380365
381366
382367@pytest .mark .parametrize ('use_binary_protocol' , [True , False ], ids = ['msgpack' , 'json' ])
383368class TestRealtimePresenceEnterClient (BaseAsyncTestCase ):
384369 """Test enterClient/updateClient/leaveClient functionality."""
385370
386371 @pytest .fixture (autouse = True )
387- async def setup (self , use_binary_protocol ):
372+ async def setup (self , use_binary_protocol , request ):
388373 """Set up test fixtures."""
389- self .test_vars = await TestApp .get_test_vars ()
390- self .use_binary_protocol = use_binary_protocol
374+ test_instance = request .instance
375+
376+ test_instance .test_vars = await TestApp .get_test_vars ()
377+ test_instance .use_binary_protocol = use_binary_protocol
391378
392379 # Use wildcard auth for enterClient
393- self .client = await TestApp .get_ably_realtime (
380+ test_instance .client = await TestApp .get_ably_realtime (
394381 client_id = '*' ,
395382 use_binary_protocol = use_binary_protocol
396383 )
397384
398385 yield
399386
400- await self .client .close ()
387+ await test_instance .client .close ()
401388
402389 async def test_enter_client_multiple (self ):
403390 """
@@ -469,10 +456,12 @@ class TestRealtimePresenceConnectionLifecycle(BaseAsyncTestCase):
469456 """Test presence behavior during connection lifecycle events."""
470457
471458 @pytest .fixture (autouse = True )
472- async def setup (self , use_binary_protocol ):
459+ async def setup (self , use_binary_protocol , request ):
473460 """Set up test fixtures."""
474- self .test_vars = await TestApp .get_test_vars ()
475- self .use_binary_protocol = use_binary_protocol
461+ test_instance = request .instance
462+
463+ test_instance .test_vars = await TestApp .get_test_vars ()
464+ test_instance .use_binary_protocol = use_binary_protocol
476465 yield
477466
478467 async def test_presence_enter_without_connect (self ):
@@ -597,10 +586,12 @@ class TestRealtimePresenceAutoReentry(BaseAsyncTestCase):
597586 """Test automatic re-entry of presence after connection suspension."""
598587
599588 @pytest .fixture (autouse = True )
600- async def setup (self , use_binary_protocol ):
589+ async def setup (self , use_binary_protocol , request ):
601590 """Set up test fixtures."""
602- self .test_vars = await TestApp .get_test_vars ()
603- self .use_binary_protocol = use_binary_protocol
591+ test_instance = request .instance
592+
593+ test_instance .test_vars = await TestApp .get_test_vars ()
594+ test_instance .use_binary_protocol = use_binary_protocol
604595 yield
605596
606597 async def test_presence_auto_reenter_after_suspend (self ):
@@ -756,10 +747,12 @@ class TestRealtimePresenceSyncBehavior(BaseAsyncTestCase):
756747 """Test presence SYNC behavior and state management."""
757748
758749 @pytest .fixture (autouse = True )
759- async def setup (self , use_binary_protocol ):
750+ async def setup (self , use_binary_protocol , request ):
760751 """Set up test fixtures."""
761- self .test_vars = await TestApp .get_test_vars ()
762- self .use_binary_protocol = use_binary_protocol
752+ test_instance = request .instance
753+
754+ test_instance .test_vars = await TestApp .get_test_vars ()
755+ test_instance .use_binary_protocol = use_binary_protocol
763756 yield
764757
765758 async def test_presence_refresh_on_detach (self ):
0 commit comments