MCPcopy
hub / github.com/google/cadvisor / TestDockerContainerRestartCount

Function TestDockerContainerRestartCount

integration/tests/api/docker_test.go:436–472  ·  view source on GitHub ↗

Check that restart count is captured in labels.

(t *testing.T)

Source from the content-addressed store, hash-verified

434
435// Check that restart count is captured in labels.
436func TestDockerContainerRestartCount(t *testing.T) {
437 fm := framework.New(t)
438 defer fm.Cleanup()
439
440 containerName := fmt.Sprintf("test-restart-count-%d", os.Getpid())
441 // Run a container that runs briefly then exits with failure, with restart policy
442 // The sleep gives cAdvisor time to detect the container between restarts
443 fm.Docker().Run(framework.DockerRunArgs{
444 Image: "registry.k8s.io/busybox:1.27",
445 Args: []string{
446 "--name", containerName,
447 "--restart", "on-failure:5",
448 },
449 }, "sh", "-c", "sleep 3 && exit 1")
450
451 // Wait for container to show up initially
452 waitForContainer(containerName, fm)
453
454 // Wait for at least one restart to occur
455 time.Sleep(5 * time.Second)
456
457 request := &info.ContainerInfoRequest{
458 NumStats: 1,
459 }
460
461 // Query the container - it should still be running or restarting
462 containerInfo, err := fm.Cadvisor().Client().DockerContainer(containerName, request)
463 require.NoError(t, err, "Container should still be available during restart cycle")
464 sanityCheck(containerName, containerInfo, t)
465
466 // Check that restart count label is present and greater than 0
467 restartCount, ok := containerInfo.Spec.Labels["restartcount"]
468 require.True(t, ok, "restartcount label should be present")
469 count, err := strconv.Atoi(restartCount)
470 require.NoError(t, err)
471 assert.GreaterOrEqual(t, count, 1, "Restart count should be at least 1")
472}
473
474// Check the DiskIo ContainerStats.
475func TestDockerContainerDiskIoStats(t *testing.T) {

Callers

nothing calls this directly

Calls 9

NewFunction · 0.92
waitForContainerFunction · 0.85
sanityCheckFunction · 0.70
CleanupMethod · 0.65
RunMethod · 0.65
DockerMethod · 0.65
DockerContainerMethod · 0.65
ClientMethod · 0.65
CadvisorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…