o
    @i                     @   sd   d dl Zd dlm  mZ d dlZd dlmZ d dl	m
Z
 G dd dejZedkr0e  dS dS )    N)patch)GpuRuntimeMonitoringServicec                   @   s$   e Zd Zdd Zdd Zdd ZdS ) GpuRuntimeMonitoringServiceTestsc                 C   s   t dd| _d S )Nr   )cache_ttl_seconds)r   service)self r   O/lsinfo/ai/hellotax_ai/base_platform/tests/services/test_gpu_runtime_service.pysetUp   s   z&GpuRuntimeMonitoringServiceTests.setUpc              	      st  ddddd d" fdd	}t j| jd	|d
& t j| jddd | j }W d    n1 s1w   Y  W d    n1 s@w   Y  | |d d d | |d d d | |d d d | |d d d d | |d d d dg | |d d d d | |d d d d | |d d d d | |d d d d | |d d d  d! d S )#Nz40, NVIDIA A100-SXM4-80GB, GPU-123, 43008, 81920, 88
zGPU-123, 4242, python, 43008
z4242 python -m vllm.entrypoints.openai.api_server --model /models/Qwen3.5-27B-AWQ --port 8100 --served-model-name Qwen3.5-27B-AWQ
zTue Apr  1 09:00:00 2026
)
nvidia-smizD--query-gpu=index,name,uuid,memory.used,memory.total,utilization.gpu--format=csv,noheader,nounitsr   z>--query-compute-apps=gpu_uuid,pid,process_name,used_gpu_memoryr   psz-eoz
pid=,args=)r   -p4242-olstart=      @c                       ~  t| S Ngettuplecommandtimeoutcommand_resultsr   r	   fake_run_command      zwGpuRuntimeMonitoringServiceTests.test_build_snapshot_maps_real_gpu_rows_and_runtime_processes.<locals>.fake_run_command_run_commandside_effect_check_service_healthTreturn_valueoverviewtotalGpuCount   runningModelCount
alertCountr   devicesstatusbusyrunningModelNameszQwen3.5-27B-AWQmodelsnamerunninggpuId0gpuNamezNVIDIA A100-SXM4-80GB #0memoryUsedGbg      E@r   r   objectr   get_snapshotassertEqualr   r    snapshotr   r   r	   <test_build_snapshot_maps_real_gpu_rows_and_runtime_processes   s,   z]GpuRuntimeMonitoringServiceTests.test_build_snapshot_maps_real_gpu_rows_and_runtime_processesc              	      s   ddddd d fdd	}t j| jd	|d
& t j| jddd | j }W d    n1 s1w   Y  W d    n1 s@w   Y  | |d d d d | |d d d d | |d d d d | |d d d d S )Nz*0, NVIDIA H100 80GB, GPU-456, 0, 81920, 0
 zf4343 python /lsinfo/ai/hellotax_ai/llm_service/servers/embedding_server.py --host 0.0.0.0 --port 8200
zTue Apr  1 08:00:00 2026
)r   r   r   )r   r   4343r   r   r   c                    r   r   r   r   r   r   r	   r    C   r!   zGpuRuntimeMonitoringServiceTests.test_build_snapshot_marks_unhealthy_service_as_failed_when_old_enough.<locals>.fake_run_commandr"   r#   r%   Fr&   r-   r   r.   onliner1   r2   zbge-m3failedr(   r,   r*   r8   r9   r=   r   r   r	   Etest_build_snapshot_marks_unhealthy_service_as_failed_when_old_enough1   s    zfGpuRuntimeMonitoringServiceTests.test_build_snapshot_marks_unhealthy_service_as_failed_when_old_enoughN)__name__
__module____qualname__r
   r?   rD   r   r   r   r	   r      s    &r   __main__)builtins@py_builtins_pytest.assertion.rewrite	assertionrewrite
@pytest_arunittestunittest.mockr   +app.services.monitoring.gpu_runtime_servicer   TestCaser   rE   mainr   r   r   r	   <module>   s   " J