MCPcopy Index your code
hub / github.com/containerd/containerd / TestContainerStats

Function TestContainerStats

integration/container_stats_test.go:33–72  ·  view source on GitHub ↗

Test to verify for a container ID

(t *testing.T)

Source from the content-addressed store, hash-verified

31
32// Test to verify for a container ID
33func TestContainerStats(t *testing.T) {
34 t.Logf("Create a pod config and run sandbox container")
35 sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox1", "stats")
36
37 pauseImage := images.Get(images.Pause)
38 EnsureImageExists(t, pauseImage)
39
40 t.Logf("Create a container config and run container in a pod")
41 containerConfig := ContainerConfig(
42 "container1",
43 pauseImage,
44 WithTestLabels(),
45 WithTestAnnotations(),
46 )
47 cn, err := runtimeService.CreateContainer(sb, containerConfig, sbConfig)
48 require.NoError(t, err)
49 defer func() {
50 assert.NoError(t, runtimeService.RemoveContainer(cn))
51 }()
52 require.NoError(t, runtimeService.StartContainer(cn))
53 defer func() {
54 assert.NoError(t, runtimeService.StopContainer(cn, 10))
55 }()
56
57 t.Logf("Fetch stats for container")
58 var s *runtime.ContainerStats
59 require.NoError(t, Eventually(func() (bool, error) {
60 s, err = runtimeService.ContainerStats(cn)
61 if err != nil {
62 return false, err
63 }
64 if s.GetWritableLayer().GetTimestamp() != 0 {
65 return true, nil
66 }
67 return false, nil
68 }, time.Second, 30*time.Second))
69
70 t.Logf("Verify stats received for container %q", cn)
71 testStats(t, s, containerConfig)
72}
73
74// Test to verify if the consumed stats are correct.
75func TestContainerConsumedStats(t *testing.T) {

Callers

nothing calls this directly

Calls 14

GetFunction · 0.92
EnsureImageExistsFunction · 0.85
ContainerConfigFunction · 0.85
WithTestLabelsFunction · 0.85
WithTestAnnotationsFunction · 0.85
EventuallyFunction · 0.85
testStatsFunction · 0.85
CreateContainerMethod · 0.65
RemoveContainerMethod · 0.65
StartContainerMethod · 0.65
StopContainerMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…