From 76d68b080ef69407129a5925ae5b97f1c9010dea Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Tue, 3 Jan 2023 22:35:10 +0900 Subject: [PATCH] container_stats_test.go: avoid checking snapshot size On Linux, the snapshot size differs depending on the backing filesystem. See issue 7909. Signed-off-by: Akihiro Suda --- integration/container_stats_test.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/integration/container_stats_test.go b/integration/container_stats_test.go index 469ce253c..0d4d458bd 100644 --- a/integration/container_stats_test.go +++ b/integration/container_stats_test.go @@ -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()) - require.NotEmpty(t, s.GetWritableLayer().GetUsedBytes().GetValue()) + + // 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" {