MCPcopy Create free account
hub / github.com/dask/dask / test_cpu_count_cgroups

Function test_cpu_count_cgroups

dask/tests/test_system.py:23–57  ·  view source on GitHub ↗
(dirname, monkeypatch)

Source from the content-addressed store, hash-verified

21
22@pytest.mark.parametrize("dirname", ["cpuacct,cpu", "cpu,cpuacct", None])
23def test_cpu_count_cgroups(dirname, monkeypatch):
24 def mycpu_count():
25 # Absurdly high, unlikely to match real value
26 return 250
27
28 monkeypatch.setattr(os, "cpu_count", mycpu_count)
29
30 class MyProcess:
31 def cpu_affinity(self):
32 # No affinity set
33 return []
34
35 monkeypatch.setattr(psutil, "Process", MyProcess)
36
37 if dirname:
38 paths = {
39 "/sys/fs/cgroup/%s/cpu.cfs_quota_us" % dirname: io.StringIO("2005"),
40 "/sys/fs/cgroup/%s/cpu.cfs_period_us" % dirname: io.StringIO("10"),
41 }
42 builtin_open = builtins.open
43
44 def myopen(path, *args, **kwargs):
45 if path in paths:
46 return paths.get(path)
47 return builtin_open(path, *args, **kwargs)
48
49 monkeypatch.setattr(builtins, "open", myopen)
50 monkeypatch.setattr(sys, "platform", "linux")
51
52 count = cpu_count()
53 if dirname:
54 # Rounds up
55 assert count == 201
56 else:
57 assert count == 250
58
59
60@pytest.mark.parametrize("group_name", ["/", "/user.slice", "/user.slice/more.slice"])

Callers

nothing calls this directly

Calls 1

cpu_countFunction · 0.90

Tested by

no test coverage detected