Skip to content

Commit 9a877a1

Browse files
committed
Add a test ensuring that just_run doesn't leak fds
1 parent 12c7f04 commit 9a877a1

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

nbclient/tests/test_util.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import asyncio
22
from unittest.mock import MagicMock
33

4+
import psutil
45
import pytest
56
import tornado
67

7-
from nbclient.util import run_hook, run_sync
8+
from nbclient.util import just_run, run_hook, run_sync
89

910

1011
@run_sync
@@ -75,3 +76,21 @@ async def test_run_hook_async():
7576
hook = MagicMock(return_value=some_async_function())
7677
await run_hook(hook)
7778
assert hook.call_count == 1
79+
80+
81+
def test_just_run_doesnt_leak_fds():
82+
proc = psutil.Process()
83+
84+
async def async_sleep():
85+
await asyncio.sleep(0.01)
86+
87+
# Warmup, just to make sure we're not failing on some initial fds being opened for the first time.
88+
for _ in range(10):
89+
just_run(async_sleep())
90+
fds_count = proc.num_fds()
91+
92+
diff = []
93+
for _ in range(10):
94+
just_run(async_sleep())
95+
diff.append(proc.num_fds() - fds_count)
96+
assert diff == [0] * 10

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ ipywidgets<8.0.0
77
mypy
88
pip>=18.1
99
pre-commit
10+
psutil
1011
pytest>=4.1
1112
pytest-asyncio
1213
pytest-cov>=2.6.1

0 commit comments

Comments
 (0)