CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
65 lines
1.5 KiB
Python
65 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Tests for memory_monitor.py"""
|
|
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
|
|
from memory_monitor import ResourceMonitor, get_storage_info, get_thread_info
|
|
|
|
|
|
def test_collect_stats():
|
|
"""Test that resource stats are collected correctly."""
|
|
monitor = ResourceMonitor(phase="Test")
|
|
stats = monitor._collect_stats()
|
|
|
|
assert "timestamp" in stats
|
|
assert stats["mem_total_gb"] > 0
|
|
assert 0 <= stats["mem_percent"] <= 100
|
|
assert 0 <= stats["swap_percent"] <= 100
|
|
assert "cpu_count" in stats
|
|
|
|
|
|
def test_storage_info():
|
|
"""Test storage info collection."""
|
|
info = get_storage_info(".")
|
|
assert info["total_gb"] > 0
|
|
assert info["free_gb"] >= 0
|
|
assert 0 <= info["percent"] <= 100
|
|
|
|
|
|
def test_thread_info():
|
|
"""Test thread/CPU info collection."""
|
|
info = get_thread_info()
|
|
assert info["cpu_count"] > 0
|
|
|
|
|
|
def test_monitor_start_stop():
|
|
"""Test starting and stopping the monitor."""
|
|
monitor = ResourceMonitor(interval=0.1, phase="Test")
|
|
|
|
monitor.start()
|
|
time.sleep(0.5)
|
|
monitor.stop()
|
|
|
|
assert len(monitor.samples) >= 1
|
|
assert monitor.stop_event.is_set()
|
|
|
|
|
|
def test_responsive_shutdown():
|
|
"""Test that stop() returns quickly even with long interval."""
|
|
monitor = ResourceMonitor(interval=60.0, phase="Test")
|
|
|
|
monitor.start()
|
|
time.sleep(0.2)
|
|
|
|
start = time.time()
|
|
monitor.stop()
|
|
elapsed = time.time() - start
|
|
|
|
assert elapsed < 3.0, f"Stop took {elapsed:.1f}s, should be < 3s"
|