MCPcopy Create free account
hub / github.com/containerd/cgroups / TestCPUQuotaPeriodUSec

Function TestCPUQuotaPeriodUSec

cgroup2/manager_test.go:404–447  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

402}
403
404func TestCPUQuotaPeriodUSec(t *testing.T) {
405 checkCgroupMode(t)
406 requireSystemdVersion(t, cpuQuotaPeriodUSecSupportedVersion)
407
408 pid := os.Getpid()
409 group := fmt.Sprintf("testing-cpu-period-%d.scope", pid)
410
411 tests := []struct {
412 name string
413 cpuMax CPUMax
414 expectedCPUMax string
415 expectedPeriod uint64
416 }{
417 {
418 name: "default cpu.max",
419 cpuMax: "max 100000",
420 expectedCPUMax: "max 100000",
421 expectedPeriod: 100000,
422 },
423 }
424
425 for _, test := range tests {
426 t.Run(test.name, func(t *testing.T) {
427 c, err := NewSystemd("", group, pid, &Resources{
428 CPU: &CPU{
429 Max: test.cpuMax,
430 },
431 })
432 require.NoError(t, err, "failed to init new cgroup systemd manager")
433
434 conn, err := systemdDbus.NewWithContext(context.TODO())
435 require.NoError(t, err, "failed to connect to systemd")
436 defer conn.Close()
437
438 unitName := systemdUnitFromPath(c.path)
439 props, err := conn.GetAllPropertiesContext(context.TODO(), unitName)
440 require.NoError(t, err, "failed to get unit properties")
441
442 periodUSec, ok := props["CPUQuotaPeriodUSec"]
443 require.True(t, ok, "CPUQuotaPeriodUSec property not found")
444 require.Equal(t, test.expectedPeriod, periodUSec.(uint64), "CPUQuotaPeriodUSec value doesn't match expected period")
445 })
446 }
447}
448
449func BenchmarkStat(b *testing.B) {
450 checkCgroupMode(b)

Callers

nothing calls this directly

Calls 4

checkCgroupModeFunction · 0.85
requireSystemdVersionFunction · 0.85
systemdUnitFromPathFunction · 0.85
NewSystemdFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…