Skip to content

Commit

Permalink
Add a test ensuring that just_run doesn't leak fds
Browse files Browse the repository at this point in the history
  • Loading branch information
mariokostelac committed Jun 28, 2022
1 parent 12c7f04 commit 9a877a1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
21 changes: 20 additions & 1 deletion nbclient/tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import asyncio
from unittest.mock import MagicMock

import psutil
import pytest
import tornado

from nbclient.util import run_hook, run_sync
from nbclient.util import just_run, run_hook, run_sync


@run_sync
Expand Down Expand Up @@ -75,3 +76,21 @@ async def test_run_hook_async():
hook = MagicMock(return_value=some_async_function())
await run_hook(hook)
assert hook.call_count == 1


def test_just_run_doesnt_leak_fds():
proc = psutil.Process()

async def async_sleep():
await asyncio.sleep(0.01)

# Warmup, just to make sure we're not failing on some initial fds being opened for the first time.
for _ in range(10):
just_run(async_sleep())
fds_count = proc.num_fds()

diff = []
for _ in range(10):
just_run(async_sleep())
diff.append(proc.num_fds() - fds_count)
assert diff == [0] * 10
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ipywidgets<8.0.0
mypy
pip>=18.1
pre-commit
psutil
pytest>=4.1
pytest-asyncio
pytest-cov>=2.6.1
Expand Down

0 comments on commit 9a877a1

Please sign in to comment.