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

Function TestContainerListStats

integration/container_stats_test.go:148–199  ·  view source on GitHub ↗

Test to verify filtering without any filter

(t *testing.T)

Source from the content-addressed store, hash-verified

146
147// Test to verify filtering without any filter
148func TestContainerListStats(t *testing.T) {
149 var (
150 stats []*runtime.ContainerStats
151 err error
152 )
153 t.Logf("Create a pod config and run sandbox container")
154 sb, sbConfig := PodSandboxConfigWithCleanup(t, "running-pod", "statsls")
155
156 pauseImage := images.Get(images.Pause)
157 EnsureImageExists(t, pauseImage)
158
159 t.Logf("Create a container config and run containers in a pod")
160 containerConfigMap := make(map[string]*runtime.ContainerConfig)
161 for i := range 3 {
162 cName := fmt.Sprintf("container%d", i)
163 containerConfig := ContainerConfig(
164 cName,
165 pauseImage,
166 WithTestLabels(),
167 WithTestAnnotations(),
168 )
169 cn, err := runtimeService.CreateContainer(sb, containerConfig, sbConfig)
170 require.NoError(t, err)
171 containerConfigMap[cn] = containerConfig
172 defer func() {
173 assert.NoError(t, runtimeService.RemoveContainer(cn))
174 }()
175 require.NoError(t, runtimeService.StartContainer(cn))
176 defer func() {
177 assert.NoError(t, runtimeService.StopContainer(cn, 10))
178 }()
179 }
180
181 t.Logf("Fetch all container stats")
182 require.NoError(t, Eventually(func() (bool, error) {
183 stats, err = runtimeService.ListContainerStats(&runtime.ContainerStatsFilter{})
184 if err != nil {
185 return false, err
186 }
187 for _, s := range stats {
188 if s.GetWritableLayer().GetTimestamp() == 0 {
189 return false, nil
190 }
191 }
192 return true, nil
193 }, time.Second, 30*time.Second))
194
195 t.Logf("Verify all container stats")
196 for _, s := range stats {
197 testStats(t, s, containerConfigMap[s.GetAttributes().GetId()])
198 }
199}
200
201// Test to verify filtering given a specific container ID
202// TODO Convert the filter tests into table driven tests and unit tests

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…