From f7b1ceb9f666c7a142f139a3306c8163866a280e Mon Sep 17 00:00:00 2001 From: Kazuyoshi Kato Date: Wed, 11 Aug 2021 15:59:58 -0700 Subject: [PATCH] integration: investigate TestRestartMonitor's failure - task.Kill() might fail in theory - Giving a longer timeout may help us understand whether the failure is a timing issue or not. Signed-off-by: Kazuyoshi Kato --- .../client/restart_monitor_linux_test.go | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/integration/client/restart_monitor_linux_test.go b/integration/client/restart_monitor_linux_test.go index f9dde83d7..cde7eeb20 100644 --- a/integration/client/restart_monitor_linux_test.go +++ b/integration/client/restart_monitor_linux_test.go @@ -34,6 +34,7 @@ func TestRestartMonitor(t *testing.T) { const ( interval = 10 * time.Second epsilon = 1 * time.Second + count = 20 ) configTOML := fmt.Sprintf(` version = 2 @@ -78,9 +79,14 @@ version = 2 t.Fatal(err) } - task.Kill(ctx, syscall.SIGKILL) + if err := task.Kill(ctx, syscall.SIGKILL); err != nil { + t.Fatal(err) + } + begin := time.Now() - deadline := begin.Add(interval).Add(epsilon) + + expected := begin.Add(interval).Add(epsilon) + deadline := begin.Add(interval).Add(epsilon * count) for { status, err := task.Status(ctx) now := time.Now() @@ -92,18 +98,21 @@ version = 2 t.Logf("%v: status=%q", now, status) if status.Status == Running { - elapsed := time.Since(begin) - t.Logf("the task was restarted within %s", elapsed.String()) - return + break } } if time.Now().After(deadline) { - break + t.Logf("%v: the task was not restarted", now) + return } time.Sleep(epsilon) } - t.Fatalf("%v: the task was not restarted in %s + %s", - time.Now(), interval.String(), epsilon.String()) + + now := time.Now() + if now.After(expected) { + t.Fatalf("%v: the task was restarted, but it must be before %v", now, expected) + } + t.Logf("%v: the task was restarted before %v", now, expected) } // withRestartStatus is a copy of "github.com/containerd/containerd/runtime/restart".WithStatus.