Skip to content

Commit

Permalink
fix testing in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
AjayThorve committed Mar 7, 2024
1 parent 2024597 commit 1e7bfe6
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 114 deletions.
7 changes: 1 addition & 6 deletions ci/test_python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ set +u
conda activate test
set -u

# rapids-logger "Downloading artifacts from previous jobs"
rapids-logger "Downloading artifacts from previous jobs"
PYTHON_CHANNEL=$(rapids-download-conda-from-s3 python)

rapids-print-env
Expand All @@ -35,12 +35,7 @@ trap "EXITCODE=1" ERR
set +e

rapids-logger "pytest jupyterlab-nvdashboard"
# Start JupyterLab in the background
python -m jupyterlab --no-browser --port=8888 --allow-root --NotebookApp.token='' --NotebookApp.password='' &
JUPYTER_PID=$!
JUPYTER_PLATFORM_DIRS=1 python -m pytest
# Shut down JupyterLab
kill $JUPYTER_PID

rapids-logger "Test script exiting with value: $EXITCODE"
exit ${EXITCODE}
5 changes: 0 additions & 5 deletions ci/test_wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ trap "EXITCODE=1" ERR
set +e

rapids-logger "pytest jupyterlab-nvdashboard"
# Start JupyterLab in the background
python -m jupyterlab --no-browser --port=8888 --allow-root --NotebookApp.token='' --NotebookApp.password='' &
JUPYTER_PID=$!
JUPYTER_PLATFORM_DIRS=1 python -m pytest
# Shut down JupyterLab
kill $JUPYTER_PID

rapids-logger "Test script exiting with value: $EXITCODE"
exit ${EXITCODE}
37 changes: 37 additions & 0 deletions jupyterlab_nvdashboard/tests/test_cpu_handlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import json
import pytest
from unittest.mock import MagicMock, patch

from jupyterlab_nvdashboard.apps.cpu import CPUResourceWebSocketHandler


@pytest.fixture
def mock_handler(monkeypatch):
mock = MagicMock()
monkeypatch.setattr(
"jupyterlab_nvdashboard.apps.cpu.CustomWebSocketHandler.write_message",
mock,
)
return mock


@pytest.fixture
def handler_args():
with patch("tornado.web.Application") as mock_application, patch(
"tornado.httputil.HTTPServerRequest"
) as mock_request:
yield mock_application, mock_request


def test_cpu_resource_handler(mock_handler, handler_args):
handler = CPUResourceWebSocketHandler(*handler_args)
handler.send_data()
args, _ = mock_handler.call_args
data = json.loads(args[0])
assert "time" in data
assert "cpu_utilization" in data
assert "memory_usage" in data
assert "disk_read" in data
assert "disk_write" in data
assert "network_read" in data
assert "network_write" in data
80 changes: 80 additions & 0 deletions jupyterlab_nvdashboard/tests/test_gpu_handlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import json
import pytest
from unittest.mock import MagicMock, patch

from jupyterlab_nvdashboard.apps.gpu import (
GPUUtilizationWebSocketHandler,
GPUUsageWebSocketHandler,
GPUResourceWebSocketHandler,
NVLinkThroughputWebSocketHandler,
PCIStatsWebSocketHandler,
)


@pytest.fixture
def mock_handler(monkeypatch):
mock = MagicMock()
monkeypatch.setattr(
"jupyterlab_nvdashboard.apps.gpu.CustomWebSocketHandler.write_message",
mock,
)
return mock


@pytest.fixture
def handler_args():
with patch("tornado.web.Application") as mock_application, patch(
"tornado.httputil.HTTPServerRequest"
) as mock_request:
yield mock_application, mock_request


def test_gpu_utilization_handler(mock_handler, handler_args):
handler = GPUUtilizationWebSocketHandler(*handler_args)
handler.send_data()
args, _ = mock_handler.call_args
data = json.loads(args[0])
assert "gpu_utilization" in data


def test_gpu_usage_handler(mock_handler, handler_args):
handler = GPUUsageWebSocketHandler(*handler_args)
handler.send_data()
args, _ = mock_handler.call_args
data = json.loads(args[0])
assert "memory_usage" in data
assert "total_memory" in data


def test_gpu_resource_handler(mock_handler, handler_args):
handler = GPUResourceWebSocketHandler(*handler_args)
handler.send_data()
args, _ = mock_handler.call_args
data = json.loads(args[0])
assert "time" in data
assert "gpu_utilization_total" in data
assert "gpu_memory_total" in data
assert "rx_total" in data
assert "tx_total" in data
assert "gpu_memory_individual" in data
assert "gpu_utilization_individual" in data


def test_nvlink_throughput_handler(mock_handler, handler_args):
handler = NVLinkThroughputWebSocketHandler(*handler_args)
handler.send_data()
args, _ = mock_handler.call_args
data = json.loads(args[0])
assert "nvlink_rx" in data
assert "nvlink_tx" in data
assert "max_rxtx_bw" in data


def test_pci_stats_handler(mock_handler, handler_args):
handler = PCIStatsWebSocketHandler(*handler_args)
handler.send_data()
args, _ = mock_handler.call_args
data = json.loads(args[0])
assert "pci_tx" in data
assert "pci_rx" in data
assert "max_rxtx_tp" in data
103 changes: 0 additions & 103 deletions jupyterlab_nvdashboard/tests/test_handlers.py

This file was deleted.

0 comments on commit 1e7bfe6

Please sign in to comment.