container_stats_test.go: avoid checking snapshot size
On Linux, the snapshot size differs depending on the backing filesystem.
See issue 7909.
@@ -61,7 +61,7 @@ func TestContainerStats(t *testing.T) {
if err != nil {
return false, err
}
- if s.GetWritableLayer().GetUsedBytes().GetValue() != 0 {
+ if s.GetWritableLayer().GetTimestamp() != 0 {
return true, nil
}
return false, nil
@@ -103,7 +103,7 @@ func TestContainerConsumedStats(t *testing.T) {
if err != nil {
return false, err
}
- if s.GetMemory().GetWorkingSetBytes().GetValue() > 0 {
+ if s.GetWritableLayer().GetTimestamp() > 0 {
return true, nil
}
return false, nil
@@ -179,7 +179,7 @@ func TestContainerListStats(t *testing.T) {
return false, err
}
for _, s := range stats {
- if s.GetWritableLayer().GetUsedBytes().GetValue() == 0 {
+ if s.GetWritableLayer().GetTimestamp() == 0 {
return false, nil
}
}
@@ -238,7 +238,7 @@ func TestContainerListStatsWithIdFilter(t *testing.T) {
if len(stats) != 1 {
return false, errors.New("unexpected stats length")
}
- if stats[0].GetWritableLayer().GetUsedBytes().GetValue() != 0 {
+ if stats[0].GetWritableLayer().GetTimestamp() != 0 {
return true, nil
}
return false, nil
@@ -300,7 +300,7 @@ func TestContainerListStatsWithSandboxIdFilter(t *testing.T) {
for _, containerStats := range stats {
// Wait for stats on all containers, not just the first one in the list.
- if containerStats.GetWritableLayer().GetUsedBytes().GetValue() == 0 {
+ if containerStats.GetWritableLayer().GetTimestamp() == 0 {
return false, nil
}
}
@@ -358,7 +358,7 @@ func TestContainerListStatsWithIdSandboxIdFilter(t *testing.T) {
if len(stats) != 1 {
return false, errors.New("unexpected stats length")
}
- if stats[0].GetWritableLayer().GetUsedBytes().GetValue() != 0 {
+ if stats[0].GetWritableLayer().GetTimestamp() != 0 {
return true, nil
}
return false, nil
@@ -380,7 +380,7 @@ func TestContainerListStatsWithIdSandboxIdFilter(t *testing.T) {
if len(stats) != 1 {
return false, fmt.Errorf("expected only one stat, but got %v", stats)
}
- if stats[0].GetWritableLayer().GetUsedBytes().GetValue() != 0 {
+ if stats[0].GetWritableLayer().GetTimestamp() != 0 {
return true, nil
}
return false, nil
@@ -410,7 +410,12 @@ func testStats(t *testing.T,
require.NotEmpty(t, s.GetMemory().GetWorkingSetBytes().GetValue())
require.NotEmpty(t, s.GetWritableLayer().GetTimestamp())
require.NotEmpty(t, s.GetWritableLayer().GetFsId().GetMountpoint())
+
+ // UsedBytes of a fresh container can be zero on Linux, depending on the backing filesystem.
+ // https://github.com/containerd/containerd/issues/7909
+ if goruntime.GOOS == "windows" {
require.NotEmpty(t, s.GetWritableLayer().GetUsedBytes().GetValue())
+ }
// Windows does not collect inodes stats.
if goruntime.GOOS != "windows" {
