Skip to content

Commit f7b1ceb

Browse files
author
Kazuyoshi Kato
committed
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 <[email protected]>
1 parent a5eccab commit f7b1ceb

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

integration/client/restart_monitor_linux_test.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func TestRestartMonitor(t *testing.T) {
3434
const (
3535
interval = 10 * time.Second
3636
epsilon = 1 * time.Second
37+
count = 20
3738
)
3839
configTOML := fmt.Sprintf(`
3940
version = 2
@@ -78,9 +79,14 @@ version = 2
7879
t.Fatal(err)
7980
}
8081

81-
task.Kill(ctx, syscall.SIGKILL)
82+
if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
83+
t.Fatal(err)
84+
}
85+
8286
begin := time.Now()
83-
deadline := begin.Add(interval).Add(epsilon)
87+
88+
expected := begin.Add(interval).Add(epsilon)
89+
deadline := begin.Add(interval).Add(epsilon * count)
8490
for {
8591
status, err := task.Status(ctx)
8692
now := time.Now()
@@ -92,18 +98,21 @@ version = 2
9298
t.Logf("%v: status=%q", now, status)
9399

94100
if status.Status == Running {
95-
elapsed := time.Since(begin)
96-
t.Logf("the task was restarted within %s", elapsed.String())
97-
return
101+
break
98102
}
99103
}
100104
if time.Now().After(deadline) {
101-
break
105+
t.Logf("%v: the task was not restarted", now)
106+
return
102107
}
103108
time.Sleep(epsilon)
104109
}
105-
t.Fatalf("%v: the task was not restarted in %s + %s",
106-
time.Now(), interval.String(), epsilon.String())
110+
111+
now := time.Now()
112+
if now.After(expected) {
113+
t.Fatalf("%v: the task was restarted, but it must be before %v", now, expected)
114+
}
115+
t.Logf("%v: the task was restarted before %v", now, expected)
107116
}
108117

109118
// withRestartStatus is a copy of "github.com/containerd/containerd/runtime/restart".WithStatus.

0 commit comments

Comments
 (0)