Skip to content

Commit e8ca233

Browse files
committed
fix test_textroom_message_history
1 parent c5f296a commit e8ca233

1 file changed

Lines changed: 42 additions & 18 deletions

File tree

tests/test_plugin_textroom.py

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -383,51 +383,75 @@ async def test_textroom_room_with_pin(self):
383383
@async_test
384384
async def test_textroom_message_history(self):
385385
"""Test message history functionality."""
386-
await self.asyncSetUp()
387-
logger.info("Testing message history")
388-
389-
session = JanusSession(transport=self.transport)
390-
plugin = JanusTextRoomPlugin()
386+
await self.attach_plugin()
391387

392-
await plugin.attach(session=session)
393-
await plugin.setup(timeout=30.0)
388+
await self.plugin.setup(timeout=30.0)
394389

395390
# Create room with history
396-
room_id = await plugin.create_room(
391+
room_id = await self.plugin.create_room(
397392
description="History Room",
398393
history=10,
399394
is_private=False,
400395
)
401396

402397
# Join and send messages
403-
await plugin.join_room(room=room_id, username="user1")
398+
await self.plugin.join_room(room=room_id, username="user1")
404399

405400
for i in range(3):
406-
await plugin.send_message(
401+
await self.plugin.send_message(
407402
room=room_id,
408403
text=f"Message {i+1}",
409404
ack=True,
410405
)
411406

412407
logger.info("Sent 3 messages")
413-
await plugin.leave_room(room=room_id)
408+
await self.plugin.leave_room(room=room_id)
409+
410+
# Track received history messages
411+
received_history = []
412+
413+
def on_message(data):
414+
received_history.append(data)
415+
logger.info(f"Received history message: {data.get('text', '')}")
416+
417+
# Register message handler before rejoining
418+
self.plugin.on_event(TextRoomEventType.MESSAGE, on_message)
414419

415420
# Rejoin and check if history is received
416-
await plugin.join_room(
421+
await self.plugin.join_room(
417422
room=room_id,
418423
username="user1",
419424
history=True,
420425
)
421426
logger.info("Rejoined room with history")
422427

423-
await asyncio.sleep(1.0)
428+
# Wait for history messages to be delivered
429+
await asyncio.sleep(2.0)
430+
431+
# Verify that we received the 3 messages from history
432+
self.assertEqual(
433+
len(received_history), 3, "Should receive 3 messages from history"
434+
)
435+
436+
# Verify message content and order
437+
for i, msg in enumerate(received_history):
438+
expected_text = f"Message {i+1}"
439+
self.assertEqual(
440+
msg.get("text"),
441+
expected_text,
442+
f"Message {i+1} text should match",
443+
)
444+
self.assertEqual(
445+
msg.get("from"), "user1", f"Message {i+1} should be from user1"
446+
)
447+
448+
logger.info("Verified message history received correctly")
424449

425450
# Clean up
426-
await plugin.leave_room(room=room_id)
427-
await plugin.destroy_room(room=room_id)
428-
await plugin.destroy()
429-
await session.destroy()
430-
await self.asyncTearDown()
451+
await self.plugin.leave_room(room=room_id)
452+
await self.plugin.destroy_room(room=room_id)
453+
454+
await self.detach_plugin()
431455

432456

433457
class TestTransportHttp(BaseTestClass.TestClass):

0 commit comments

Comments
 (0)