Skip to content

Commit 5e3a6df

Browse files
kiashokKirtana Ashok
andauthored
Fix graceful termination test errors (#1687)
- Loosen the time interval check that measures the time taken to stop the container with -t command to account for cloud test delays - Add to check that OS version is V21H2Server since the graceful termination test images are based on servercore and nanoserver 2022. Signed-off-by: Kirtana Ashok <[email protected]> Co-authored-by: Kirtana Ashok <[email protected]>
1 parent 69815bc commit 5e3a6df

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

test/cri-containerd/stopcontainer_test.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ package cri_containerd
55

66
import (
77
"context"
8+
"math"
89
"testing"
910
"time"
1011

12+
"github.com/Microsoft/hcsshim/osversion"
13+
"github.com/Microsoft/hcsshim/test/internal/require"
1114
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
1215
)
1316

@@ -178,6 +181,10 @@ func Test_StopContainer_ReusePod_LCOW(t *testing.T) {
178181
// behavior and to ensure that the containers are killed only after 15 second
179182
// timeout specified via the stop container command.
180183
func Test_GracefulTermination(t *testing.T) {
184+
// The test image is based on 2022 servercore and nanoserver images. Ensure
185+
// that we are running on the correct OS version
186+
require.Build(t, osversion.V21H2Server)
187+
181188
for name, tc := range map[string]struct {
182189
features []string
183190
runtimeHandler string
@@ -235,13 +242,13 @@ func Test_GracefulTermination(t *testing.T) {
235242
startTimeOfContainer := time.Now()
236243
// stop container with timeout of 15 seconds
237244
stopContainerWithTimeout(t, client, ctx, containerID, 15)
238-
assertContainerState(t, client, ctx, containerID, runtime.ContainerState_CONTAINER_EXITED)
239245
// get time elapsed before and after container stop command was issued
240-
elapsedTime := time.Since(startTimeOfContainer)
246+
elapsedTime := math.Round(time.Since(startTimeOfContainer).Seconds())
247+
assertContainerState(t, client, ctx, containerID, runtime.ContainerState_CONTAINER_EXITED)
241248
// Ensure that the container has stopped after approx 15 seconds.
242-
// We are giving it a buffer of +/- 1 second
243-
if elapsedTime < 14*time.Second || elapsedTime > 16*time.Second {
244-
t.Fatalf("Container did not shutdown gracefully \n")
249+
// We are giving it a buffer of few seconds to account for cloud test delays
250+
if elapsedTime < 14 || elapsedTime > 20 {
251+
t.Fatalf("Container did not shutdown gracefully. Total elapsedTime before and after container stop command was issued is: %v", elapsedTime)
245252
}
246253
})
247254
}

0 commit comments

Comments
 (0)