1- // +build linux
2-
31/*
42 Copyright The containerd Authors.
53
@@ -40,6 +38,9 @@ func TestContainerStats(t *testing.T) {
4038 assert .NoError (t , runtimeService .StopPodSandbox (sb ))
4139 assert .NoError (t , runtimeService .RemovePodSandbox (sb ))
4240 }()
41+
42+ EnsureImageExists (t , pauseImage )
43+
4344 t .Logf ("Create a container config and run container in a pod" )
4445 containerConfig := ContainerConfig (
4546 "container1" ,
@@ -64,8 +65,7 @@ func TestContainerStats(t *testing.T) {
6465 if err != nil {
6566 return false , err
6667 }
67- if s .GetWritableLayer ().GetUsedBytes ().GetValue () != 0 &&
68- s .GetWritableLayer ().GetInodesUsed ().GetValue () != 0 {
68+ if s .GetWritableLayer ().GetUsedBytes ().GetValue () != 0 {
6969 return true , nil
7070 }
7171 return false , nil
@@ -162,6 +162,9 @@ func TestContainerListStats(t *testing.T) {
162162 assert .NoError (t , runtimeService .StopPodSandbox (sb ))
163163 assert .NoError (t , runtimeService .RemovePodSandbox (sb ))
164164 }()
165+
166+ EnsureImageExists (t , pauseImage )
167+
165168 t .Logf ("Create a container config and run containers in a pod" )
166169 containerConfigMap := make (map [string ]* runtime.ContainerConfig )
167170 for i := 0 ; i < 3 ; i ++ {
@@ -192,8 +195,7 @@ func TestContainerListStats(t *testing.T) {
192195 return false , err
193196 }
194197 for _ , s := range stats {
195- if s .GetWritableLayer ().GetUsedBytes ().GetValue () == 0 &&
196- s .GetWritableLayer ().GetInodesUsed ().GetValue () == 0 {
198+ if s .GetWritableLayer ().GetUsedBytes ().GetValue () == 0 {
197199 return false , nil
198200 }
199201 }
@@ -217,6 +219,9 @@ func TestContainerListStatsWithIdFilter(t *testing.T) {
217219 assert .NoError (t , runtimeService .StopPodSandbox (sb ))
218220 assert .NoError (t , runtimeService .RemovePodSandbox (sb ))
219221 }()
222+
223+ EnsureImageExists (t , pauseImage )
224+
220225 t .Logf ("Create a container config and run containers in a pod" )
221226 containerConfigMap := make (map [string ]* runtime.ContainerConfig )
222227 for i := 0 ; i < 3 ; i ++ {
@@ -251,8 +256,7 @@ func TestContainerListStatsWithIdFilter(t *testing.T) {
251256 if len (stats ) != 1 {
252257 return false , errors .New ("unexpected stats length" )
253258 }
254- if stats [0 ].GetWritableLayer ().GetUsedBytes ().GetValue () != 0 &&
255- stats [0 ].GetWritableLayer ().GetInodesUsed ().GetValue () != 0 {
259+ if stats [0 ].GetWritableLayer ().GetUsedBytes ().GetValue () != 0 {
256260 return true , nil
257261 }
258262 return false , nil
@@ -277,6 +281,9 @@ func TestContainerListStatsWithSandboxIdFilter(t *testing.T) {
277281 assert .NoError (t , runtimeService .StopPodSandbox (sb ))
278282 assert .NoError (t , runtimeService .RemovePodSandbox (sb ))
279283 }()
284+
285+ EnsureImageExists (t , pauseImage )
286+
280287 t .Logf ("Create a container config and run containers in a pod" )
281288 containerConfigMap := make (map [string ]* runtime.ContainerConfig )
282289 for i := 0 ; i < 3 ; i ++ {
@@ -310,12 +317,12 @@ func TestContainerListStatsWithSandboxIdFilter(t *testing.T) {
310317 if len (stats ) != 3 {
311318 return false , errors .New ("unexpected stats length" )
312319 }
313- if stats [0 ].GetWritableLayer ().GetUsedBytes ().GetValue () != 0 &&
314- stats [0 ].GetWritableLayer ().GetInodesUsed ().GetValue () != 0 {
320+ if stats [0 ].GetWritableLayer ().GetUsedBytes ().GetValue () != 0 {
315321 return true , nil
316322 }
317323 return false , nil
318- }, time .Second , 30 * time .Second ))
324+ }, time .Second , 45 * time .Second ))
325+ // TODO(claudiub): Reduce the timer above to 30 seconds once Windows flakiness has been addressed.
319326 t .Logf ("Verify container stats for sandbox %q" , sb )
320327 for _ , s := range stats {
321328 testStats (t , s , containerConfigMap [s .GetAttributes ().GetId ()])
@@ -333,6 +340,9 @@ func TestContainerListStatsWithIdSandboxIdFilter(t *testing.T) {
333340 assert .NoError (t , runtimeService .StopPodSandbox (sb ))
334341 assert .NoError (t , runtimeService .RemovePodSandbox (sb ))
335342 }()
343+
344+ EnsureImageExists (t , pauseImage )
345+
336346 t .Logf ("Create container config and run containers in a pod" )
337347 containerConfigMap := make (map [string ]* runtime.ContainerConfig )
338348 for i := 0 ; i < 3 ; i ++ {
@@ -366,8 +376,7 @@ func TestContainerListStatsWithIdSandboxIdFilter(t *testing.T) {
366376 if len (stats ) != 1 {
367377 return false , errors .New ("unexpected stats length" )
368378 }
369- if stats [0 ].GetWritableLayer ().GetUsedBytes ().GetValue () != 0 &&
370- stats [0 ].GetWritableLayer ().GetInodesUsed ().GetValue () != 0 {
379+ if stats [0 ].GetWritableLayer ().GetUsedBytes ().GetValue () != 0 {
371380 return true , nil
372381 }
373382 return false , nil
@@ -389,8 +398,7 @@ func TestContainerListStatsWithIdSandboxIdFilter(t *testing.T) {
389398 if len (stats ) != 1 {
390399 return false , errors .New ("unexpected stats length" )
391400 }
392- if stats [0 ].GetWritableLayer ().GetUsedBytes ().GetValue () != 0 &&
393- stats [0 ].GetWritableLayer ().GetInodesUsed ().GetValue () != 0 {
401+ if stats [0 ].GetWritableLayer ().GetUsedBytes ().GetValue () != 0 {
394402 return true , nil
395403 }
396404 return false , nil
@@ -421,5 +429,9 @@ func testStats(t *testing.T,
421429 require .NotEmpty (t , s .GetWritableLayer ().GetTimestamp ())
422430 require .NotEmpty (t , s .GetWritableLayer ().GetFsId ().GetMountpoint ())
423431 require .NotEmpty (t , s .GetWritableLayer ().GetUsedBytes ().GetValue ())
424- require .NotEmpty (t , s .GetWritableLayer ().GetInodesUsed ().GetValue ())
432+
433+ // Windows does not collect inodes stats.
434+ if goruntime .GOOS != "windows" {
435+ require .NotEmpty (t , s .GetWritableLayer ().GetInodesUsed ().GetValue ())
436+ }
425437}
0 commit comments