Skip to content

Commit 0403f0d

Browse files
ndeloofglours
authored andcommittedApr 30, 2025·
e2e test for start_interval
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
1 parent 91d04a5 commit 0403f0d

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed
 

‎pkg/compose/convert.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ func (s *composeService) ToMobyHealthCheck(ctx context.Context, check *compose.H
7878
} else {
7979
startInterval = time.Duration(*check.StartInterval)
8080
}
81+
if check.StartPeriod == nil {
82+
// see https://github.com/moby/moby/issues/48874
83+
return nil, errors.New("healthcheck.start_interval requires healthcheck.start_period to be set")
84+
}
8185
}
8286
return &container.HealthConfig{
8387
Test: test,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
services:
2+
test:
3+
image: "nginx"
4+
healthcheck:
5+
interval: 30s
6+
start_period: 10s
7+
start_interval: 1s
8+
test: "/bin/true"
9+
10+
error:
11+
image: "nginx"
12+
healthcheck:
13+
interval: 30s
14+
start_interval: 1s
15+
test: "/bin/true"

‎pkg/e2e/healthcheck_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
Copyright 2023 Docker Compose CLI authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package e2e
18+
19+
import (
20+
"strings"
21+
"testing"
22+
"time"
23+
24+
"gotest.tools/v3/assert"
25+
"gotest.tools/v3/icmd"
26+
)
27+
28+
func TestStartInterval(t *testing.T) {
29+
c := NewParallelCLI(t)
30+
const projectName = "e2e-start-interval"
31+
32+
t.Cleanup(func() {
33+
c.cleanupWithDown(t, projectName)
34+
})
35+
36+
res := c.RunDockerComposeCmdNoCheck(t, "-f", "fixtures/start_interval/compose.yaml", "--project-name", projectName, "up", "--wait", "-d", "error")
37+
res.Assert(t, icmd.Expected{ExitCode: 1, Err: "healthcheck.start_interval requires healthcheck.start_period to be set"})
38+
39+
timeout := time.After(30 * time.Second)
40+
done := make(chan bool)
41+
go func() {
42+
res := c.RunDockerComposeCmd(t, "-f", "fixtures/start_interval/compose.yaml", "--project-name", projectName, "up", "--wait", "-d", "test")
43+
out := res.Combined()
44+
assert.Assert(t, strings.Contains(out, "Healthy"), out)
45+
done <- true
46+
}()
47+
48+
select {
49+
case <-timeout:
50+
t.Fatal("test did not finish in time")
51+
case <-done:
52+
break
53+
}
54+
}

0 commit comments

Comments
 (0)
Please sign in to comment.