(quota, group_name, monkeypatch, monkeypatch_cpu_count)
| 132 | @pytest.mark.parametrize("group_name", ["/", "/user.slice", "/user.slice/more.slice"]) |
| 133 | @pytest.mark.parametrize("quota", ["max", "2005"]) |
| 134 | def test_cpu_count_cgroups_v2(quota, group_name, monkeypatch, monkeypatch_cpu_count): |
| 135 | if not group_name.endswith("/"): |
| 136 | group_name = f"{group_name}/" |
| 137 | |
| 138 | paths = { |
| 139 | "/proc/self/cgroup": io.StringIO(f"0::{group_name}"), |
| 140 | f"/sys/fs/cgroup{group_name}cpu.max": io.StringIO(f"{quota} 10"), |
| 141 | } |
| 142 | builtin_open = builtins.open |
| 143 | |
| 144 | def myopen(path, *args, **kwargs): |
| 145 | if path in paths: |
| 146 | return paths.get(path) |
| 147 | return builtin_open(path, *args, **kwargs) |
| 148 | |
| 149 | monkeypatch.setattr(builtins, "open", myopen) |
| 150 | monkeypatch.setattr(sys, "platform", "linux") |
| 151 | |
| 152 | count = cpu_count() |
| 153 | if quota == "max": |
| 154 | assert count == 250 |
| 155 | else: |
| 156 | # Rounds up |
| 157 | assert count == 201 |
nothing calls this directly
no test coverage detected