Skip to content

Commit

Permalink
rename opts
Browse files Browse the repository at this point in the history
  • Loading branch information
keroxp committed Jun 25, 2024
1 parent 615f6bc commit ff3850d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 18 deletions.
30 changes: 17 additions & 13 deletions cli/cage/commands/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,48 +43,52 @@ 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,
}
}

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,
}
}
8 changes: 4 additions & 4 deletions env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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),
Expand All @@ -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")
Expand Down
31 changes: 31 additions & 0 deletions timeout/timeout_test.go
Original file line number Diff line number Diff line change
@@ -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())
})
}

0 comments on commit ff3850d

Please sign in to comment.