-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #365 from afshin/ensure_last_activity
Culling: ensure last_activity attr exists before use
- Loading branch information
Showing
8 changed files
with
195 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Jupyter Server Tests [Mac OS] | ||
on: | ||
push: | ||
branches: '*' | ||
pull_request: | ||
branches: '*' | ||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }}-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [macos] | ||
python-version: [ '3.6', '3.7', '3.8', '3.9', 'pypy3' ] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v1 | ||
- name: Install Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
architecture: 'x64' | ||
- name: Upgrade packaging dependencies | ||
run: | | ||
pip install --upgrade pip setuptools wheel --user | ||
- name: Get pip cache dir | ||
id: pip-cache | ||
run: | | ||
echo "::set-output name=dir::$(pip cache dir)" | ||
- name: Cache pip | ||
uses: actions/cache@v1 | ||
with: | ||
path: ${{ steps.pip-cache.outputs.dir }} | ||
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py') }} | ||
restore-keys: | | ||
${{ runner.os }}-pip-${{ matrix.python-version }}- | ||
${{ runner.os }}-pip- | ||
- name: Install the Python dependencies | ||
run: | | ||
pip install -e .[test] codecov | ||
- name: List installed packages | ||
run: | | ||
pip freeze | ||
pip check | ||
- name: Run the tests | ||
run: | | ||
pytest -vv --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered | ||
- name: Install the Python dependencies for the examples | ||
run: | | ||
cd examples/simple && pip install -e . | ||
- name: Run the tests for the examples | ||
run: | | ||
pytest examples/simple/tests/test_handlers.py | ||
- name: Coverage | ||
run: | | ||
codecov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Jupyter Server Tests [Windows] | ||
on: | ||
push: | ||
branches: '*' | ||
pull_request: | ||
branches: '*' | ||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }}-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [windows] | ||
python-version: [ '3.6', '3.7', '3.8', '3.9' ] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v1 | ||
- name: Install Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
architecture: 'x64' | ||
- name: Upgrade packaging dependencies | ||
run: | | ||
pip install --upgrade pip setuptools wheel --user | ||
- name: Get pip cache dir | ||
id: pip-cache | ||
run: | | ||
echo "::set-output name=dir::$(pip cache dir)" | ||
- name: Cache pip | ||
uses: actions/cache@v1 | ||
with: | ||
path: ${{ steps.pip-cache.outputs.dir }} | ||
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py') }} | ||
restore-keys: | | ||
${{ runner.os }}-pip-${{ matrix.python-version }}- | ||
${{ runner.os }}-pip- | ||
- name: Install the Python dependencies | ||
run: | | ||
pip install -e .[test] codecov | ||
- name: List installed packages | ||
run: | | ||
pip freeze | ||
pip check | ||
- name: Run the tests | ||
run: | | ||
pytest -vv | ||
- name: Install the Python dependencies for the examples | ||
run: | | ||
cd examples/simple && pip install -e . | ||
- name: Run the tests for the examples | ||
run: | | ||
pytest examples/simple/tests/test_handlers.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import asyncio | ||
import json | ||
import platform | ||
import sys | ||
import time | ||
import pytest | ||
from traitlets.config import Config | ||
from tornado.httpclient import HTTPClientError | ||
|
||
|
||
@pytest.fixture(params=["MappingKernelManager", "AsyncMappingKernelManager"]) | ||
def jp_argv(request): | ||
return ["--ServerApp.kernel_manager_class=jupyter_server.services.kernels.kernelmanager." + request.param] | ||
|
||
|
||
CULL_TIMEOUT = 10 if platform.python_implementation() == 'PyPy' else 2 | ||
|
||
@pytest.fixture | ||
def jp_server_config(): | ||
return Config({ | ||
'ServerApp': { | ||
'MappingKernelManager': { | ||
'cull_idle_timeout': CULL_TIMEOUT, | ||
'cull_interval': 1, | ||
'cull_connected': False | ||
} | ||
} | ||
}) | ||
|
||
|
||
async def test_culling(jp_fetch, jp_ws_fetch): | ||
r = await jp_fetch( | ||
'api', 'kernels', | ||
method='POST', | ||
allow_nonstandard_methods=True | ||
) | ||
kernel = json.loads(r.body.decode()) | ||
kid = kernel['id'] | ||
|
||
# Open a websocket connection. | ||
ws = await jp_ws_fetch( | ||
'api', 'kernels', kid, 'channels' | ||
) | ||
|
||
r = await jp_fetch( | ||
'api', 'kernels', kid, | ||
method='GET' | ||
) | ||
model = json.loads(r.body.decode()) | ||
assert model['connections'] == 1 | ||
culled = await get_cull_status(kid, jp_fetch) # connected, should not be culled | ||
assert not culled | ||
ws.close() | ||
culled = await get_cull_status(kid, jp_fetch) # not connected, should be culled | ||
assert culled | ||
|
||
|
||
async def get_cull_status(kid, jp_fetch): | ||
culled = False | ||
for i in range(20): # Need max of 2x culling PERIOD ensure culling timeout exceeded | ||
try: | ||
r = await jp_fetch( | ||
'api', 'kernels', kid, | ||
method='GET' | ||
) | ||
kernel = json.loads(r.body.decode()) | ||
except HTTPClientError as e: | ||
assert e.code == 404 | ||
culled = True | ||
break | ||
else: | ||
await asyncio.sleep(CULL_TIMEOUT / 10.) | ||
return culled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters