Skip to content

Commit b850fb6

Browse files
committed
test
1 parent 7ae9391 commit b850fb6

File tree

2 files changed

+47
-76
lines changed

2 files changed

+47
-76
lines changed

ably/realtime/realtimepresence.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,6 @@ async def _send_presence(self, presence_messages: list[dict]) -> None:
362362
'presence': presence_messages
363363
}
364364

365-
print(
366-
f"[PRESENCE DEBUG] _send_presence: Sending {len(presence_messages)} messages "
367-
f"on channel {self.channel.name}"
368-
)
369365
await self.channel.ably.connection.connection_manager.send_protocol_message(protocol_msg)
370366

371367
async def _queue_presence(self, wire_msg: dict) -> None:
@@ -472,10 +468,6 @@ async def subscribe(self, *args) -> None:
472468
Raises:
473469
AblyException: If channel state prevents subscription
474470
"""
475-
print(
476-
f"[PRESENCE DEBUG] subscribe: Called on channel {self.channel.name}, "
477-
f"channel.state={self.channel.state}"
478-
)
479471
# RTP6d: Implicitly attach
480472
if self.channel.state in [ChannelState.INITIALIZED, ChannelState.DETACHED, ChannelState.DETACHING]:
481473
asyncio.create_task(self.channel.attach())
@@ -485,13 +477,11 @@ async def subscribe(self, *args) -> None:
485477
# subscribe(listener)
486478
listener = args[0]
487479
self._subscriptions.on(listener)
488-
print("[PRESENCE DEBUG] subscribe: Registered listener for all events")
489480
elif len(args) == 2:
490481
# subscribe(event, listener)
491482
event = args[0]
492483
listener = args[1]
493484
self._subscriptions.on(event, listener)
494-
print(f"[PRESENCE DEBUG] subscribe: Registered listener for event '{event}'")
495485
else:
496486
raise ValueError('Invalid subscribe arguments')
497487

@@ -534,10 +524,6 @@ def set_presence(
534524
is_sync: True if this is part of a SYNC operation
535525
sync_channel_serial: Optional sync cursor for tracking sync progress
536526
"""
537-
print(
538-
f"[PRESENCE DEBUG] set_presence: Received {len(presence_set)} messages "
539-
f"on channel {self.channel.name}, is_sync={is_sync}"
540-
)
541527
log.info(
542528
f'RealtimePresence.set_presence(): '
543529
f'received presence for {len(presence_set)} members; '
@@ -602,16 +588,8 @@ def set_presence(
602588
broadcast_messages.append(synthesized_leave)
603589

604590
# Broadcast messages to subscribers
605-
print(
606-
f"[PRESENCE DEBUG] set_presence: Broadcasting {len(broadcast_messages)} messages "
607-
f"to subscribers on channel {self.channel.name}"
608-
)
609591
for presence in broadcast_messages:
610592
action_name = PresenceAction._action_name(presence.action).lower()
611-
print(
612-
f"[PRESENCE DEBUG] set_presence: Emitting '{action_name}' "
613-
f"for client_id={presence.client_id}"
614-
)
615593
self._subscriptions._emit(action_name, presence)
616594

617595
def on_attached(self, has_presence: bool = False) -> None:

test/ably/realtime/realtimepresence_test.py

Lines changed: 47 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -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'])
383368
class 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

Comments
 (0)