moby--moby/integration-cli/docker_cli_service_health_t...

141 lines
4.9 KiB
Go
Raw Normal View History

//go:build !windows
// +build !windows
package main
import (
"strconv"
"strings"
"testing"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/daemon/cluster/executor/container"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/cli"
"github.com/docker/docker/integration-cli/cli/build"
"gotest.tools/v3/assert"
"gotest.tools/v3/icmd"
"gotest.tools/v3/poll"
)
// start a service, and then make its task unhealthy during running
// finally, unhealthy task should be detected and killed
rm-gocheck: check.C -> testing.T sed -E -i 's#\bcheck\.C\b#testing.T#g' \ -- "integration-cli/check_test.go" "integration-cli/daemon/daemon.go" "integration-cli/daemon/daemon_swarm.go" "integration-cli/daemon_swarm_hack_test.go" "integration-cli/docker_api_attach_test.go" "integration-cli/docker_api_build_test.go" "integration-cli/docker_api_build_windows_test.go" "integration-cli/docker_api_containers_test.go" "integration-cli/docker_api_containers_windows_test.go" "integration-cli/docker_api_exec_resize_test.go" "integration-cli/docker_api_exec_test.go" "integration-cli/docker_api_images_test.go" "integration-cli/docker_api_inspect_test.go" "integration-cli/docker_api_logs_test.go" "integration-cli/docker_api_network_test.go" "integration-cli/docker_api_stats_test.go" "integration-cli/docker_api_swarm_node_test.go" "integration-cli/docker_api_swarm_service_test.go" "integration-cli/docker_api_swarm_test.go" "integration-cli/docker_api_test.go" "integration-cli/docker_cli_attach_test.go" "integration-cli/docker_cli_attach_unix_test.go" "integration-cli/docker_cli_build_test.go" "integration-cli/docker_cli_build_unix_test.go" "integration-cli/docker_cli_by_digest_test.go" "integration-cli/docker_cli_commit_test.go" "integration-cli/docker_cli_cp_from_container_test.go" "integration-cli/docker_cli_cp_test.go" "integration-cli/docker_cli_cp_to_container_test.go" "integration-cli/docker_cli_cp_to_container_unix_test.go" "integration-cli/docker_cli_cp_utils_test.go" "integration-cli/docker_cli_create_test.go" "integration-cli/docker_cli_daemon_plugins_test.go" "integration-cli/docker_cli_daemon_test.go" "integration-cli/docker_cli_events_test.go" "integration-cli/docker_cli_events_unix_test.go" "integration-cli/docker_cli_exec_test.go" "integration-cli/docker_cli_exec_unix_test.go" "integration-cli/docker_cli_external_volume_driver_unix_test.go" "integration-cli/docker_cli_health_test.go" "integration-cli/docker_cli_history_test.go" "integration-cli/docker_cli_images_test.go" "integration-cli/docker_cli_import_test.go" "integration-cli/docker_cli_info_test.go" "integration-cli/docker_cli_info_unix_test.go" "integration-cli/docker_cli_inspect_test.go" "integration-cli/docker_cli_links_test.go" "integration-cli/docker_cli_login_test.go" "integration-cli/docker_cli_logout_test.go" "integration-cli/docker_cli_logs_test.go" "integration-cli/docker_cli_netmode_test.go" "integration-cli/docker_cli_network_unix_test.go" "integration-cli/docker_cli_plugins_logdriver_test.go" "integration-cli/docker_cli_plugins_test.go" "integration-cli/docker_cli_port_test.go" "integration-cli/docker_cli_proxy_test.go" "integration-cli/docker_cli_prune_unix_test.go" "integration-cli/docker_cli_ps_test.go" "integration-cli/docker_cli_pull_local_test.go" "integration-cli/docker_cli_pull_test.go" "integration-cli/docker_cli_push_test.go" "integration-cli/docker_cli_registry_user_agent_test.go" "integration-cli/docker_cli_restart_test.go" "integration-cli/docker_cli_rmi_test.go" "integration-cli/docker_cli_run_test.go" "integration-cli/docker_cli_run_unix_test.go" "integration-cli/docker_cli_save_load_test.go" "integration-cli/docker_cli_save_load_unix_test.go" "integration-cli/docker_cli_search_test.go" "integration-cli/docker_cli_service_create_test.go" "integration-cli/docker_cli_service_health_test.go" "integration-cli/docker_cli_service_logs_test.go" "integration-cli/docker_cli_service_scale_test.go" "integration-cli/docker_cli_sni_test.go" "integration-cli/docker_cli_start_test.go" "integration-cli/docker_cli_stats_test.go" "integration-cli/docker_cli_swarm_test.go" "integration-cli/docker_cli_swarm_unix_test.go" "integration-cli/docker_cli_top_test.go" "integration-cli/docker_cli_update_unix_test.go" "integration-cli/docker_cli_userns_test.go" "integration-cli/docker_cli_v2_only_test.go" "integration-cli/docker_cli_volume_test.go" "integration-cli/docker_deprecated_api_v124_test.go" "integration-cli/docker_deprecated_api_v124_unix_test.go" "integration-cli/docker_hub_pull_suite_test.go" "integration-cli/docker_utils_test.go" "integration-cli/events_utils_test.go" "integration-cli/fixtures_linux_daemon_test.go" "integration-cli/utils_test.go" "pkg/discovery/discovery_test.go" "pkg/discovery/file/file_test.go" "pkg/discovery/generator_test.go" "pkg/discovery/kv/kv_test.go" "pkg/discovery/memory/memory_test.go" "pkg/discovery/nodes/nodes_test.go" Signed-off-by: Tibor Vass <tibor@docker.com>
2019-09-09 21:05:55 +00:00
func (s *DockerSwarmSuite) TestServiceHealthRun(c *testing.T) {
testRequires(c, DaemonIsLinux) // busybox doesn't work on Windows
d := s.AddDaemon(c, true, true)
// build image with health-check
imageName := "testhealth"
result := cli.BuildCmd(c, imageName, cli.Daemon(d),
build.WithDockerfile(`FROM busybox
RUN touch /status
HEALTHCHECK --interval=1s --timeout=5s --retries=1\
CMD cat /status`),
)
result.Assert(c, icmd.Success)
serviceName := "healthServiceRun"
out, err := d.Cmd("service", "create", "--no-resolve-image", "--detach=true", "--name", serviceName, imageName, "top")
assert.NilError(c, err, out)
id := strings.TrimSpace(out)
var tasks []swarm.Task
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
tasks = d.GetServiceTasks(c, id)
rm-gocheck: fix compile errors from converting check.CommentInterface to string while :; do \ out=$(go test -c ./integration-cli 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./integration-cli/daemon 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/file 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/kv 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/memory 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/nodes 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done Signed-off-by: Tibor Vass <tibor@docker.com>
2019-09-09 21:09:27 +00:00
return tasks, ""
}, checker.HasLen(1)), poll.WithTimeout(defaultReconciliationTimeout))
task := tasks[0]
// wait for task to start
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
task = d.GetTask(c, task.ID)
rm-gocheck: fix compile errors from converting check.CommentInterface to string while :; do \ out=$(go test -c ./integration-cli 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./integration-cli/daemon 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/file 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/kv 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/memory 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/nodes 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done Signed-off-by: Tibor Vass <tibor@docker.com>
2019-09-09 21:09:27 +00:00
return task.Status.State, ""
}, checker.Equals(swarm.TaskStateRunning)), poll.WithTimeout(defaultReconciliationTimeout))
containerID := task.Status.ContainerStatus.ContainerID
// wait for container to be healthy
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
out, _ := d.Cmd("inspect", "--format={{.State.Health.Status}}", containerID)
rm-gocheck: fix compile errors from converting check.CommentInterface to string while :; do \ out=$(go test -c ./integration-cli 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./integration-cli/daemon 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/file 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/kv 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/memory 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/nodes 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done Signed-off-by: Tibor Vass <tibor@docker.com>
2019-09-09 21:09:27 +00:00
return strings.TrimSpace(out), ""
}, checker.Equals("healthy")), poll.WithTimeout(defaultReconciliationTimeout))
// make it fail
d.Cmd("exec", containerID, "rm", "/status")
// wait for container to be unhealthy
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
out, _ := d.Cmd("inspect", "--format={{.State.Health.Status}}", containerID)
rm-gocheck: fix compile errors from converting check.CommentInterface to string while :; do \ out=$(go test -c ./integration-cli 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./integration-cli/daemon 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/file 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/kv 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/memory 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/nodes 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done Signed-off-by: Tibor Vass <tibor@docker.com>
2019-09-09 21:09:27 +00:00
return strings.TrimSpace(out), ""
}, checker.Equals("unhealthy")), poll.WithTimeout(defaultReconciliationTimeout))
// Task should be terminated
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
task = d.GetTask(c, task.ID)
rm-gocheck: fix compile errors from converting check.CommentInterface to string while :; do \ out=$(go test -c ./integration-cli 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./integration-cli/daemon 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/file 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/kv 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/memory 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/nodes 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done Signed-off-by: Tibor Vass <tibor@docker.com>
2019-09-09 21:09:27 +00:00
return task.Status.State, ""
}, checker.Equals(swarm.TaskStateFailed)), poll.WithTimeout(defaultReconciliationTimeout))
if !strings.Contains(task.Status.Err, container.ErrContainerUnhealthy.Error()) {
c.Fatal("unhealthy task exits because of other error")
}
}
// start a service whose task is unhealthy at beginning
// its tasks should be blocked in starting stage, until health check is passed
rm-gocheck: check.C -> testing.T sed -E -i 's#\bcheck\.C\b#testing.T#g' \ -- "integration-cli/check_test.go" "integration-cli/daemon/daemon.go" "integration-cli/daemon/daemon_swarm.go" "integration-cli/daemon_swarm_hack_test.go" "integration-cli/docker_api_attach_test.go" "integration-cli/docker_api_build_test.go" "integration-cli/docker_api_build_windows_test.go" "integration-cli/docker_api_containers_test.go" "integration-cli/docker_api_containers_windows_test.go" "integration-cli/docker_api_exec_resize_test.go" "integration-cli/docker_api_exec_test.go" "integration-cli/docker_api_images_test.go" "integration-cli/docker_api_inspect_test.go" "integration-cli/docker_api_logs_test.go" "integration-cli/docker_api_network_test.go" "integration-cli/docker_api_stats_test.go" "integration-cli/docker_api_swarm_node_test.go" "integration-cli/docker_api_swarm_service_test.go" "integration-cli/docker_api_swarm_test.go" "integration-cli/docker_api_test.go" "integration-cli/docker_cli_attach_test.go" "integration-cli/docker_cli_attach_unix_test.go" "integration-cli/docker_cli_build_test.go" "integration-cli/docker_cli_build_unix_test.go" "integration-cli/docker_cli_by_digest_test.go" "integration-cli/docker_cli_commit_test.go" "integration-cli/docker_cli_cp_from_container_test.go" "integration-cli/docker_cli_cp_test.go" "integration-cli/docker_cli_cp_to_container_test.go" "integration-cli/docker_cli_cp_to_container_unix_test.go" "integration-cli/docker_cli_cp_utils_test.go" "integration-cli/docker_cli_create_test.go" "integration-cli/docker_cli_daemon_plugins_test.go" "integration-cli/docker_cli_daemon_test.go" "integration-cli/docker_cli_events_test.go" "integration-cli/docker_cli_events_unix_test.go" "integration-cli/docker_cli_exec_test.go" "integration-cli/docker_cli_exec_unix_test.go" "integration-cli/docker_cli_external_volume_driver_unix_test.go" "integration-cli/docker_cli_health_test.go" "integration-cli/docker_cli_history_test.go" "integration-cli/docker_cli_images_test.go" "integration-cli/docker_cli_import_test.go" "integration-cli/docker_cli_info_test.go" "integration-cli/docker_cli_info_unix_test.go" "integration-cli/docker_cli_inspect_test.go" "integration-cli/docker_cli_links_test.go" "integration-cli/docker_cli_login_test.go" "integration-cli/docker_cli_logout_test.go" "integration-cli/docker_cli_logs_test.go" "integration-cli/docker_cli_netmode_test.go" "integration-cli/docker_cli_network_unix_test.go" "integration-cli/docker_cli_plugins_logdriver_test.go" "integration-cli/docker_cli_plugins_test.go" "integration-cli/docker_cli_port_test.go" "integration-cli/docker_cli_proxy_test.go" "integration-cli/docker_cli_prune_unix_test.go" "integration-cli/docker_cli_ps_test.go" "integration-cli/docker_cli_pull_local_test.go" "integration-cli/docker_cli_pull_test.go" "integration-cli/docker_cli_push_test.go" "integration-cli/docker_cli_registry_user_agent_test.go" "integration-cli/docker_cli_restart_test.go" "integration-cli/docker_cli_rmi_test.go" "integration-cli/docker_cli_run_test.go" "integration-cli/docker_cli_run_unix_test.go" "integration-cli/docker_cli_save_load_test.go" "integration-cli/docker_cli_save_load_unix_test.go" "integration-cli/docker_cli_search_test.go" "integration-cli/docker_cli_service_create_test.go" "integration-cli/docker_cli_service_health_test.go" "integration-cli/docker_cli_service_logs_test.go" "integration-cli/docker_cli_service_scale_test.go" "integration-cli/docker_cli_sni_test.go" "integration-cli/docker_cli_start_test.go" "integration-cli/docker_cli_stats_test.go" "integration-cli/docker_cli_swarm_test.go" "integration-cli/docker_cli_swarm_unix_test.go" "integration-cli/docker_cli_top_test.go" "integration-cli/docker_cli_update_unix_test.go" "integration-cli/docker_cli_userns_test.go" "integration-cli/docker_cli_v2_only_test.go" "integration-cli/docker_cli_volume_test.go" "integration-cli/docker_deprecated_api_v124_test.go" "integration-cli/docker_deprecated_api_v124_unix_test.go" "integration-cli/docker_hub_pull_suite_test.go" "integration-cli/docker_utils_test.go" "integration-cli/events_utils_test.go" "integration-cli/fixtures_linux_daemon_test.go" "integration-cli/utils_test.go" "pkg/discovery/discovery_test.go" "pkg/discovery/file/file_test.go" "pkg/discovery/generator_test.go" "pkg/discovery/kv/kv_test.go" "pkg/discovery/memory/memory_test.go" "pkg/discovery/nodes/nodes_test.go" Signed-off-by: Tibor Vass <tibor@docker.com>
2019-09-09 21:05:55 +00:00
func (s *DockerSwarmSuite) TestServiceHealthStart(c *testing.T) {
testRequires(c, DaemonIsLinux) // busybox doesn't work on Windows
d := s.AddDaemon(c, true, true)
// service started from this image won't pass health check
imageName := "testhealth"
result := cli.BuildCmd(c, imageName, cli.Daemon(d),
build.WithDockerfile(`FROM busybox
HEALTHCHECK --interval=1s --timeout=1s --retries=1024\
CMD cat /status`),
)
result.Assert(c, icmd.Success)
serviceName := "healthServiceStart"
out, err := d.Cmd("service", "create", "--no-resolve-image", "--detach=true", "--name", serviceName, imageName, "top")
assert.NilError(c, err, out)
id := strings.TrimSpace(out)
var tasks []swarm.Task
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
tasks = d.GetServiceTasks(c, id)
rm-gocheck: fix compile errors from converting check.CommentInterface to string while :; do \ out=$(go test -c ./integration-cli 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./integration-cli/daemon 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/file 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/kv 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/memory 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/nodes 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done Signed-off-by: Tibor Vass <tibor@docker.com>
2019-09-09 21:09:27 +00:00
return tasks, ""
}, checker.HasLen(1)), poll.WithTimeout(defaultReconciliationTimeout))
task := tasks[0]
// wait for task to start
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
task = d.GetTask(c, task.ID)
rm-gocheck: fix compile errors from converting check.CommentInterface to string while :; do \ out=$(go test -c ./integration-cli 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./integration-cli/daemon 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/file 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/kv 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/memory 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/nodes 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done Signed-off-by: Tibor Vass <tibor@docker.com>
2019-09-09 21:09:27 +00:00
return task.Status.State, ""
}, checker.Equals(swarm.TaskStateStarting)), poll.WithTimeout(defaultReconciliationTimeout))
containerID := task.Status.ContainerStatus.ContainerID
// wait for health check to work
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
out, _ := d.Cmd("inspect", "--format={{.State.Health.FailingStreak}}", containerID)
failingStreak, _ := strconv.Atoi(strings.TrimSpace(out))
rm-gocheck: fix compile errors from converting check.CommentInterface to string while :; do \ out=$(go test -c ./integration-cli 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./integration-cli/daemon 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/file 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/kv 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/memory 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/nodes 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done Signed-off-by: Tibor Vass <tibor@docker.com>
2019-09-09 21:09:27 +00:00
return failingStreak, ""
}, checker.GreaterThan(0)), poll.WithTimeout(defaultReconciliationTimeout))
// task should be blocked at starting status
task = d.GetTask(c, task.ID)
rm-gocheck: Equals -> assert.Equal sed -E -i 's#\bassert\.Assert\(c, (.*), checker\.Equals, (.*)#assert.Equal(c, \1, \2#g' \ -- "integration-cli/docker_api_containers_test.go" "integration-cli/docker_api_swarm_node_test.go" "integration-cli/docker_cli_attach_test.go" "integration-cli/docker_cli_build_test.go" "integration-cli/docker_cli_build_unix_test.go" "integration-cli/docker_cli_by_digest_test.go" "integration-cli/docker_cli_commit_test.go" "integration-cli/docker_cli_create_test.go" "integration-cli/docker_cli_daemon_test.go" "integration-cli/docker_cli_external_volume_driver_unix_test.go" "integration-cli/docker_cli_health_test.go" "integration-cli/docker_cli_images_test.go" "integration-cli/docker_cli_import_test.go" "integration-cli/docker_cli_info_test.go" "integration-cli/docker_cli_inspect_test.go" "integration-cli/docker_cli_links_test.go" "integration-cli/docker_cli_network_unix_test.go" "integration-cli/docker_cli_plugins_test.go" "integration-cli/docker_cli_port_test.go" "integration-cli/docker_cli_ps_test.go" "integration-cli/docker_cli_rmi_test.go" "integration-cli/docker_cli_run_test.go" "integration-cli/docker_cli_run_unix_test.go" "integration-cli/docker_cli_service_create_test.go" "integration-cli/docker_cli_service_health_test.go" "integration-cli/docker_cli_start_test.go" "integration-cli/docker_cli_swarm_test.go" "integration-cli/docker_cli_userns_test.go" "integration-cli/docker_cli_volume_test.go" "pkg/discovery/discovery_test.go" "pkg/discovery/file/file_test.go" "pkg/discovery/generator_test.go" "pkg/discovery/kv/kv_test.go" "pkg/discovery/nodes/nodes_test.go" Signed-off-by: Tibor Vass <tibor@docker.com>
2019-09-09 21:05:56 +00:00
assert.Equal(c, task.Status.State, swarm.TaskStateStarting)
// make it healthy
d.Cmd("exec", containerID, "touch", "/status")
// Task should be at running status
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
task = d.GetTask(c, task.ID)
rm-gocheck: fix compile errors from converting check.CommentInterface to string while :; do \ out=$(go test -c ./integration-cli 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./integration-cli/daemon 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/file 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/kv 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/memory 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done \ && \ while :; do \ out=$(go test -c ./pkg/discovery/nodes 2>&1 | grep 'cannot use nil as type string in return argument') || break echo "$out" | while read line; do file=$(echo "$line" | cut -d: -f1) n=$(echo "$line" | cut -d: -f2) sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file" done done Signed-off-by: Tibor Vass <tibor@docker.com>
2019-09-09 21:09:27 +00:00
return task.Status.State, ""
}, checker.Equals(swarm.TaskStateRunning)), poll.WithTimeout(defaultReconciliationTimeout))
}