@@ -84,6 +84,19 @@ async def test_process_before_response(self):
8484 # no sleep here
8585 assert self .mock_received_requests ["/chat.postMessage" ] == 1
8686
87+ @pytest .mark .asyncio
88+ async def test_middleware_skip (self ):
89+ app = AsyncApp (
90+ client = self .web_client ,
91+ signing_secret = self .signing_secret
92+ )
93+ app .event ("app_mention" , middleware = [skip_middleware ])(whats_up )
94+
95+ request = self .build_valid_app_mention_request ()
96+ response = await app .async_dispatch (request )
97+ assert response .status == 404
98+ assert self .mock_received_requests ["/auth.test" ] == 1
99+
87100 @pytest .mark .asyncio
88101 async def test_simultaneous_requests (self ):
89102 app = AsyncApp (
@@ -95,27 +108,17 @@ async def test_simultaneous_requests(self):
95108 request = self .build_valid_app_mention_request ()
96109
97110 times = 10
111+ tasks = []
98112 for i in range (times ):
99- asyncio .ensure_future (app .async_dispatch (request ))
113+ tasks . append ( asyncio .ensure_future (app .async_dispatch (request ) ))
100114
101115 await asyncio .sleep (5 )
116+ # Verifies all the tasks have been completed with 200 OK
117+ assert sum ([t .result ().status for t in tasks if t .done ()]) == 200 * times
102118
103119 assert self .mock_received_requests ["/auth.test" ] == times
104120 assert self .mock_received_requests ["/chat.postMessage" ] == times
105121
106- @pytest .mark .asyncio
107- async def test_middleware_skip (self ):
108- app = AsyncApp (
109- client = self .web_client ,
110- signing_secret = self .signing_secret
111- )
112- app .event ("app_mention" , middleware = [skip_middleware ])(whats_up )
113-
114- request = self .build_valid_app_mention_request ()
115- response = await app .async_dispatch (request )
116- assert response .status == 404
117- assert self .mock_received_requests ["/auth.test" ] == 1
118-
119122
120123app_mention_payload = {
121124 "token" : "verification_token" ,
@@ -141,7 +144,7 @@ async def test_middleware_skip(self):
141144
142145async def random_sleeper (payload , say ):
143146 assert payload == app_mention_payload
144- seconds = random () + 2 # 2-3 seconds
147+ seconds = random () + 2 # 2-3 seconds
145148 await asyncio .sleep (seconds )
146149 await say (f"Sending this message after sleeping for { seconds } seconds" )
147150
0 commit comments