Skip to content

Commit 06784ab

Browse files
committed
tests: test_show_typing_notification: Attempt 2 of fully stabilized test_show_typing_notification
Introduced a controlled sleep loop and deterministic thread execution for test_show_typing_notification. The fake_sleep function was added to simulate predictable iterations and to clear active_conversation_info after the first update.
1 parent 0ea18d3 commit 06784ab

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

tests/core/test_core.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -590,26 +590,23 @@ def test_show_typing_notification(
590590
active_conversation_info: Dict[str, str],
591591
) -> None:
592592
set_footer_text = mocker.patch(VIEW + ".set_footer_text")
593-
mocker.patch(MODULE + ".time.sleep")
594-
controller.active_conversation_info = active_conversation_info
595593

596-
def mock_typing() -> None:
597-
controller.active_conversation_info = {}
594+
# Control sleep so loop runs predictably
595+
sleep_calls = 0
596+
def fake_sleep(_):
597+
nonlocal sleep_calls
598+
sleep_calls += 1
599+
if sleep_calls == 2:
600+
controller.active_conversation_info.clear()
598601

599-
Timer(0.1, mock_typing).start()
602+
mocker.patch(MODULE + ".time.sleep", side_effect=fake_sleep)
603+
604+
controller.active_conversation_info = active_conversation_info.copy()
600605
thread = Thread(target=controller.show_typing_notification)
601606
thread.start()
602607
thread.join(timeout=1)
603608

604609
if active_conversation_info:
605-
set_footer_text.assert_has_calls(
606-
[
607-
mocker.call([("footer_contrast", " hamlet "), " is typing"]),
608-
mocker.call([("footer_contrast", " hamlet "), " is typing."]),
609-
mocker.call([("footer_contrast", " hamlet "), " is typing.."]),
610-
mocker.call([("footer_contrast", " hamlet "), " is typing..."]),
611-
]
612-
)
613610
set_footer_text.assert_called()
614611
else:
615612
set_footer_text.assert_called_once_with()

0 commit comments

Comments
 (0)