|
| 1 | +######################################################################### |
| 2 | +# test_slurmctld.py - slurmctld unit tests |
| 3 | +######################################################################### |
| 4 | +# Copyright (C) 2025 Toni Harzendorf <[email protected]> |
| 5 | +# |
| 6 | +# This file is part of PySlurm |
| 7 | +# |
| 8 | +# PySlurm is free software; you can redistribute it and/or modify |
| 9 | +# it under the terms of the GNU General Public License as published by |
| 10 | +# the Free Software Foundation; either version 2 of the License, or |
| 11 | +# (at your option) any later version. |
| 12 | + |
| 13 | +# PySlurm is distributed in the hope that it will be useful, |
| 14 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | +# GNU General Public License for more details. |
| 17 | +# |
| 18 | +# You should have received a copy of the GNU General Public License along |
| 19 | +# with PySlurm; if not, write to the Free Software Foundation, Inc., |
| 20 | +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | +"""test_slurmctld.py - Unit test basic slurmctld functionalities.""" |
| 22 | + |
| 23 | +import pyslurm |
| 24 | +from pyslurm import slurmctld |
| 25 | +from pyslurm.core.slurmctld.stats import _parse_test_data |
| 26 | + |
| 27 | + |
| 28 | +def test_statistics(): |
| 29 | + stats = _parse_test_data() |
| 30 | + assert stats.to_dict() |
| 31 | + |
| 32 | + assert len(stats.rpcs_by_type) == 3 |
| 33 | + for typ, val in stats.rpcs_by_type.items(): |
| 34 | + assert val.count > 0 |
| 35 | + assert val.time > 0 |
| 36 | + assert val.average_time > 0 |
| 37 | + assert typ is not None |
| 38 | + |
| 39 | + assert len(stats.rpcs_pending) == 5 |
| 40 | + for typ, val in stats.rpcs_pending.items(): |
| 41 | + assert val.count > 0 |
| 42 | + assert typ is not None |
| 43 | + assert isinstance(typ, str) |
| 44 | + |
| 45 | + assert len(stats.rpcs_by_user) == 1 |
| 46 | + for typ, val in stats.rpcs_by_user.items(): |
| 47 | + assert val.user_id == 0 |
| 48 | + assert val.user_name == "root" |
| 49 | + assert val.time > 0 |
| 50 | + assert val.average_time > 0 |
| 51 | + assert typ is not None |
| 52 | + |
| 53 | + assert stats.schedule_exit |
| 54 | + assert stats.backfill_exit |
| 55 | + assert stats.jobs_submitted == 20 |
| 56 | + assert stats.jobs_running == 3 |
| 57 | + assert stats.schedule_cycle_last == 40 |
| 58 | + assert stats.schedule_cycle_sum == 45 |
| 59 | + assert stats.schedule_cycle_mean == 4 |
| 60 | + assert stats.schedule_cycle_counter == 10 |
| 61 | + |
| 62 | + assert stats.backfill_cycle_counter == 100 |
| 63 | + assert stats.backfill_active is False |
| 64 | + assert stats.backfilled_jobs == 10 |
| 65 | + assert stats.backfill_cycle_sum == 200 |
| 66 | + assert stats.backfill_depth_try_sum == 300 |
| 67 | + assert stats.backfill_queue_length_sum == 600 |
| 68 | + assert stats.backfill_table_size_sum == 200 |
| 69 | + assert stats.backfill_cycle_mean == 2 |
0 commit comments