(t *testing.T)
| 402 | } |
| 403 | |
| 404 | func 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 | |
| 449 | func BenchmarkStat(b *testing.B) { |
| 450 | checkCgroupMode(b) |
nothing calls this directly
no test coverage detected
searching dependent graphs…