diff --git a/cli/cage/commands/flags.go b/cli/cage/commands/flags.go index cd651d9..0ce5d4f 100644 --- a/cli/cage/commands/flags.go +++ b/cli/cage/commands/flags.go @@ -43,7 +43,7 @@ func CanaryTaskIdleDurationFlag(dest *int) *cli.IntFlag { return &cli.IntFlag{ Name: "canaryTaskIdleDuration", EnvVars: []string{cage.CanaryTaskIdleDuration}, - Usage: "Idle duration seconds for ensuring canary task that has no attached load balancer", + Usage: "duration seconds for waiting canary task that isn't attached to target group considered as ready for serving traffic", Destination: dest, Value: 10, } @@ -51,40 +51,44 @@ func CanaryTaskIdleDurationFlag(dest *int) *cli.IntFlag { func TaskRunningWaitFlag(dest *int) *cli.IntFlag { return &cli.IntFlag{ - Name: "canaryTaskRunningWait", - EnvVars: []string{cage.CanaryTaskRunningWait}, - Usage: "Duration seconds for waiting canary task running", + Name: "taskRunningTimeout", + EnvVars: []string{cage.TaskRunningTimeout}, + Usage: "max duration seconds for waiting canary task running", Destination: dest, + Category: "ADVANCED", Value: 300, } } func TaskHealthCheckWaitFlag(dest *int) *cli.IntFlag { return &cli.IntFlag{ - Name: "canaryTaskHealthCheckWait", - EnvVars: []string{cage.CanaryTaskHealthCheckWait}, - Usage: "Duration seconds for waiting canary task health check", + Name: "taskHealthCheckTimeout", + EnvVars: []string{cage.TaskHealthCheckTimeout}, + Usage: "max duration seconds for waiting canary task health check", Destination: dest, + Category: "ADVANCED", Value: 300, } } func TaskStoppedWaitFlag(dest *int) *cli.IntFlag { return &cli.IntFlag{ - Name: "canaryTaskStoppedWait", - EnvVars: []string{cage.CanaryTaskStoppedWait}, - Usage: "Duration seconds for waiting canary task stopped", + Name: "taskStoppedTimeout", + EnvVars: []string{cage.TaskStoppedTimeout}, + Usage: "max duration seconds for waiting canary task stopped", Destination: dest, + Category: "ADVANCED", Value: 300, } } func ServiceStableWaitFlag(dest *int) *cli.IntFlag { return &cli.IntFlag{ - Name: "serviceStableWait", - EnvVars: []string{cage.ServiceStableWait}, - Usage: "Duration seconds for waiting service stable", + Name: "serviceStableTimeout", + EnvVars: []string{cage.ServiceStableTimeout}, + Usage: "max duration seconds for waiting service stable", Destination: dest, + Category: "ADVANCED", Value: 300, } } diff --git a/env.go b/env.go index 8cfcac4..a47c310 100644 --- a/env.go +++ b/env.go @@ -39,10 +39,10 @@ const CanaryInstanceArnKey = "CAGE_CANARY_INSTANCE_ARN" const RegionKey = "CAGE_REGION" const CanaryTaskIdleDuration = "CAGE_CANARY_TASK_IDLE_DURATION" const UpdateServiceKey = "CAGE_UPDATE_SERVIEC" -const CanaryTaskRunningWait = "CAGE_CANARY_TASK_RUNNING_WAIT" -const CanaryTaskHealthCheckWait = "CAGE_CANARY_TASK_HEALTH_CHECK_WAIT" -const CanaryTaskStoppedWait = "CAGE_CANARY_TASK_STOPPED_WAIT" -const ServiceStableWait = "CAGE_SERVICE_STABLE_WAIT" +const TaskRunningTimeout = "CAGE_TASK_RUNNING_TIMEOUT" +const TaskHealthCheckTimeout = "CAGE_TASK_HEALTH_CHECK_TIMEOUT" +const TaskStoppedTimeout = "CAGE_TASK_STOPPED_TIMEOUT" +const ServiceStableTimeout = "CAGE_SERVICE_STABLE_TIMEOUT" func EnsureEnvars( dest *Envars, diff --git a/run_test.go b/run_test.go index f5fe733..146c739 100644 --- a/run_test.go +++ b/run_test.go @@ -55,6 +55,7 @@ func TestCage_Run(t *testing.T) { container := "container" ctx := context.Background() env, mocker, ecsMock := setupForBasic(t) + env.CanaryTaskRunningWait = 1 gomock.InOrder( ecsMock.EXPECT().RunTask(gomock.Any(), gomock.Any()).DoAndReturn(mocker.RunTask), ecsMock.EXPECT().DescribeTasks(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn( @@ -85,6 +86,7 @@ func TestCage_Run(t *testing.T) { container := "container" ctx := context.Background() env, mocker, ecsMock := setupForBasic(t) + env.CanaryTaskStoppedWait = 1 gomock.InOrder( ecsMock.EXPECT().RunTask(gomock.Any(), gomock.Any()).DoAndReturn(mocker.RunTask), ecsMock.EXPECT().DescribeTasks(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(mocker.DescribeTasks).Times(2), @@ -97,7 +99,6 @@ func TestCage_Run(t *testing.T) { result, err := cagecli.Run(ctx, &cage.RunInput{ Container: &container, Overrides: overrides, - // MaxWait: 1, }) assert.Nil(t, result) assert.EqualError(t, err, "task failed to stop: exceeded max wait time for TasksStopped waiter") diff --git a/timeout/timeout_test.go b/timeout/timeout_test.go new file mode 100644 index 0000000..f03e2ff --- /dev/null +++ b/timeout/timeout_test.go @@ -0,0 +1,31 @@ +package timeout_test + +import ( + "testing" + "time" + + "github.com/loilo-inc/canarycage/timeout" + "github.com/stretchr/testify/assert" +) + +func TestManager(t *testing.T) { + t.Run("no configu", func(t *testing.T) { + man := timeout.NewManager(10, &timeout.Input{}) + assert.Equal(t, time.Duration(10), man.TaskRunning()) + assert.Equal(t, time.Duration(10), man.TaskStopped()) + assert.Equal(t, time.Duration(10), man.TaskHealthCheck()) + assert.Equal(t, time.Duration(10), man.ServiceStable()) + }) + t.Run("with config", func(t *testing.T) { + man := timeout.NewManager(10, &timeout.Input{ + TaskRunningWait: 1, + TaskStoppedWait: 2, + TaskHealthCheckWait: 3, + ServiceStableWait: 4, + }) + assert.Equal(t, time.Duration(1), man.TaskRunning()) + assert.Equal(t, time.Duration(2), man.TaskStopped()) + assert.Equal(t, time.Duration(3), man.TaskHealthCheck()) + assert.Equal(t, time.Duration(4), man.ServiceStable()) + }) +}