Skip to content

Commit 3190afb

Browse files
committed
ShowTypingActivities Middleware bug
It doesn't stop sending activities, this commit is just the test showing the failure. Under TDD principles
1 parent 13ee2f2 commit 3190afb

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

libraries/botbuilder-core/botbuilder/core/adapters/test_adapter.py

+1
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ async def wait_for_activity():
699699
reply = adapter.activity_buffer.pop(0)
700700
raise RuntimeError(
701701
f"TestAdapter.assert_no_reply(): '{reply.text}' is responded when waiting for no reply."
702+
f"(Activity type: {reply.type})"
702703
)
703704

704705
await asyncio.sleep(0.05)

libraries/botbuilder-core/tests/test_show_typing_middleware.py

+24-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from uuid import uuid4
55
import aiounittest
66

7-
from botbuilder.core import ShowTypingMiddleware, TurnContext
8-
from botbuilder.core.adapters import TestAdapter
7+
from botbuilder.core import Middleware, ShowTypingMiddleware, TurnContext
8+
from botbuilder.core.adapters import TestAdapter, TestFlow
99
from botbuilder.schema import Activity, ActivityTypes
1010
from botframework.connector.auth import AuthenticationConstants, ClaimsIdentity
1111

@@ -47,6 +47,28 @@ def assert_is_typing(activity, description): # pylint: disable=unused-argument
4747
step5 = await step4.assert_reply(assert_is_typing)
4848
await step5.assert_reply("echo:bar")
4949

50+
async def test_should_stop_sendind_typing_indicators_when_exception_raised(self):
51+
async def aux(context):
52+
await context.send_activity(f"echo:{context.activity.text}")
53+
raise Exception("test:error")
54+
55+
class ErrorHandlingMiddleware(Middleware):
56+
async def on_turn(self, context, logic):
57+
try:
58+
await logic()
59+
except Exception as e:
60+
await context.send_activity(f"error:{e.args[0]}")
61+
62+
adapter = TestAdapter(aux)
63+
64+
adapter.use(ErrorHandlingMiddleware())
65+
adapter.use(ShowTypingMiddleware(0.2, 0.4))
66+
67+
step1: TestFlow = await adapter.send("foo")
68+
step2 = await step1.assert_reply("echo:foo")
69+
step2 = await step1.assert_reply("error:test:error")
70+
await step2.assert_no_reply("no typing activity should be shown", timeout=450)
71+
5072
async def test_should_not_automatically_send_a_typing_indicator_if_no_middleware(
5173
self,
5274
):

0 commit comments

Comments
 (0)