(dirname, monkeypatch, monkeypatch_cpu_count)
| 105 | @pytest.mark.skipif(not LINUX, reason="Control Groups only available on Linux") |
| 106 | @pytest.mark.parametrize("dirname", ["cpuacct,cpu", "cpu,cpuacct", None]) |
| 107 | def test_cpu_count_cgroups(dirname, monkeypatch, monkeypatch_cpu_count): |
| 108 | if dirname: |
| 109 | paths = { |
| 110 | f"/sys/fs/cgroup/{dirname}/cpu.cfs_quota_us": io.StringIO("2005"), |
| 111 | f"/sys/fs/cgroup/{dirname}/cpu.cfs_period_us": io.StringIO("10"), |
| 112 | } |
| 113 | builtin_open = builtins.open |
| 114 | |
| 115 | def myopen(path, *args, **kwargs): |
| 116 | if path in paths: |
| 117 | return paths.get(path) |
| 118 | return builtin_open(path, *args, **kwargs) |
| 119 | |
| 120 | monkeypatch.setattr(builtins, "open", myopen) |
| 121 | monkeypatch.setattr(sys, "platform", "linux") |
| 122 | |
| 123 | count = cpu_count() |
| 124 | if dirname: |
| 125 | # Rounds up |
| 126 | assert count == 201 |
| 127 | else: |
| 128 | assert count == 250 |
| 129 | |
| 130 | |
| 131 | @pytest.mark.skipif(not LINUX, reason="Control Groups only available on Linux") |
nothing calls this directly
no test coverage detected