Skip to content

Commit 2800312

Browse files
committed
Add test
1 parent 4609e8b commit 2800312

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 AsyncPeriodicExecutors do not copy ContextVars from their parents."""
16+
from __future__ import annotations
17+
18+
import asyncio
19+
import sys
20+
from test.asynchronous.utils import async_get_pool
21+
from test.utils_shared import delay, one
22+
23+
sys.path[0:0] = [""]
24+
25+
from test.asynchronous import AsyncIntegrationTest
26+
27+
28+
class TestAsyncContextVarsReset(AsyncIntegrationTest):
29+
async def test_context_vars_are_reset_in_executor(self):
30+
client = self.simple_client()
31+
32+
await client.db.test.insert_one({"x": 1})
33+
for server in client._topology._servers.values():
34+
for context in [
35+
c
36+
for c in server._monitor._executor._task.get_context()
37+
if c.name in ["TIMEOUT", "RTT", "DEADLINE"]
38+
]:
39+
self.assertIn(context.get(), [None, float("inf"), 0.0])
40+
await client.db.test.delete_many({})

tools/synchro.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ def async_only_test(f: str) -> bool:
185185
"test_concurrency.py",
186186
"test_async_cancellation.py",
187187
"test_async_loop_safety.py",
188+
"test_async_contextvars_reset.py",
188189
]
189190

190191

0 commit comments

Comments
 (0)