File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change
1
+ # Copyright 2025-present MongoDB, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Test that async cancellation performed by users raises the expected error."""
16
+ from __future__ import annotations
17
+
18
+ import asyncio
19
+ import sys
20
+
21
+ sys .path [0 :0 ] = ["" ]
22
+
23
+ from test .asynchronous import AsyncIntegrationTest
24
+
25
+
26
+ class TestAsyncCancellation (AsyncIntegrationTest ):
27
+ async def test_async_cancellation (self ):
28
+ async def task ():
29
+ while True :
30
+ await self .client .db .test .insert_one ({"x" : 1 })
31
+ await asyncio .sleep (0.005 )
32
+
33
+ task = asyncio .create_task (task ())
34
+
35
+ # Make sure the task successfully runs a few operations to simulate a long-running user task
36
+ await asyncio .sleep (0.01 )
37
+
38
+ task .cancel ()
39
+ with self .assertRaises (asyncio .CancelledError ):
40
+ await task
Original file line number Diff line number Diff line change 168
168
169
169
def async_only_test (f : str ) -> bool :
170
170
"""Return True for async tests that should not be converted to sync."""
171
- return f in ["test_locks.py" , "test_concurrency.py" ]
171
+ return f in ["test_locks.py" , "test_concurrency.py" , "test_async_cancellation.py" ]
172
172
173
173
174
174
test_files = [
You can’t perform that action at this time.
0 commit comments