-
Notifications
You must be signed in to change notification settings - Fork 56
1. TypingIndicator Concurrency & Argument fixes #187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1afacc6
1. TypingIndicator Class (typing_indicator.py)
cleemullins e904cdc
Fix interval conversion in TypingIndicator class constructor
cleemullins 7ad1698
Fix duplicate raise statement in TypingIndicator class
cleemullins 41b340c
Refactor TypingIndicator class for improved concurrency and add unit …
cleemullins 2fc9788
Merge branch 'main' into users/cleemullins/TypingIndicatorFixes
cleemullins 422d245
Refactor TypingIndicator to use seconds for interval tracking and log…
cleemullins 8041865
Merge branch 'users/cleemullins/TypingIndicatorFixes' of https://gith…
cleemullins 737194c
Fix error handling in typing loop to reset task on failure
cleemullins 724095f
Refactor logging statements in TypingIndicator for improved readability
cleemullins f4779dc
Fix typing loop error handling to ensure task state is managed correctly
cleemullins 1385744
Merge branch 'main' of https://github.com/microsoft/Agents-for-python…
rodrigobr-msft e82f104
Making TypingIndicator local variable to _on_turn
rodrigobr-msft 8c1a677
Merge branch 'users/cleemullins/TypingIndicatorFixes' of https://gith…
rodrigobr-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import asyncio | ||
|
|
||
| import pytest | ||
|
|
||
| from microsoft_agents.activity import Activity, ActivityTypes | ||
| from microsoft_agents.hosting.core.app.typing_indicator import TypingIndicator | ||
|
|
||
|
|
||
| class StubTurnContext: | ||
| """Test double that tracks sent activities.""" | ||
|
|
||
| def __init__(self, should_raise: bool = False) -> None: | ||
| self.sent_activities = [] | ||
| self.should_raise = should_raise | ||
|
|
||
| async def send_activity(self, activity: Activity): | ||
| if self.should_raise: | ||
| raise RuntimeError("send_activity failure") | ||
| self.sent_activities.append(activity) | ||
| return None | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_start_sends_typing_activity(): | ||
| context = StubTurnContext() | ||
| indicator = TypingIndicator(intervalSeconds=0.01) | ||
|
|
||
| await indicator.start(context) | ||
| await asyncio.sleep(0.03) | ||
| await indicator.stop() | ||
|
|
||
| assert len(context.sent_activities) >= 1 | ||
| assert all(activity.type == ActivityTypes.typing for activity in context.sent_activities) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_start_is_idempotent(): | ||
| context = StubTurnContext() | ||
| indicator = TypingIndicator(intervalSeconds=0.01) | ||
|
|
||
| await indicator.start(context) | ||
| first_task = indicator._task # noqa: SLF001 - accessing for test verification | ||
|
|
||
| await indicator.start(context) | ||
| second_task = indicator._task # noqa: SLF001 | ||
|
|
||
| assert first_task is second_task | ||
|
|
||
| await indicator.stop() | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_stop_without_start_is_noop(): | ||
| indicator = TypingIndicator() | ||
|
|
||
| await indicator.stop() | ||
|
|
||
| assert indicator._task is None # noqa: SLF001 | ||
| assert indicator._running is False # noqa: SLF001 | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_typing_loop_stops_on_send_error(): | ||
| context = StubTurnContext(should_raise=True) | ||
| indicator = TypingIndicator(intervalSeconds=0.01) | ||
|
|
||
| await indicator.start(context) | ||
| await asyncio.sleep(0.02) | ||
|
|
||
| assert indicator._task is not None # noqa: SLF001 | ||
| await asyncio.wait_for(indicator._task, timeout=0.1) # Ensure loop exits | ||
|
|
||
| assert indicator._running is False # noqa: SLF001 | ||
| assert indicator._task.done() # noqa: SLF001 | ||
|
|
||
| await indicator.stop() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.