do not wait for dependencies with scale 0

Signed-off-by: Guillaume Lours <guillaume.lours@docker.com>
This commit is contained in:
Guillaume Lours 2022-02-19 21:17:51 +01:00
parent 416498441c
commit 09e0fa94b8
2 changed files with 25 additions and 0 deletions

View File

@ -280,6 +280,12 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr
// already managed by InDependencyOrder // already managed by InDependencyOrder
return nil return nil
} }
if service, err := project.GetService(dep); err != nil {
return err
} else if service.Scale == 0 {
// don't wait for the dependency which configured to have 0 containers running
continue
}
containers, err := s.getContainers(ctx, project.Name, oneOffExclude, false, dep) containers, err := s.getContainers(ctx, project.Name, oneOffExclude, false, dep)
if err != nil { if err != nil {

View File

@ -19,6 +19,7 @@ package compose
import ( import (
"context" "context"
"fmt" "fmt"
"strings"
"testing" "testing"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/types"
@ -184,3 +185,21 @@ func TestServiceLinks(t *testing.T) {
assert.Equal(t, links[2], "testProject-web-1:testProject-web-1") assert.Equal(t, links[2], "testProject-web-1:testProject-web-1")
}) })
} }
func TestWaitDependencies(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
api := mocks.NewMockAPIClient(mockCtrl)
tested.apiClient = api
t.Run("should skip dependencies with scale 0", func(t *testing.T) {
dbService := types.ServiceConfig{Name: "db", Scale: 0}
redisService := types.ServiceConfig{Name: "redis", Scale: 0}
project := types.Project{Name: strings.ToLower(testProject), Services: []types.ServiceConfig{dbService, redisService}}
dependencies := types.DependsOnConfig{
"db": {Condition: ServiceConditionRunningOrHealthy},
"redis": {Condition: ServiceConditionRunningOrHealthy},
}
assert.NilError(t, tested.waitDependencies(context.Background(), &project, dependencies))
})
}