Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
amogh09 committed Apr 29, 2024
1 parent 2b1ad1b commit 78a1bfa
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
33 changes: 33 additions & 0 deletions ecs-agent/utils/retry/constant_backoff.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

package retry

import "time"

// A simple backoff strategy that backs off the same amount of time for each iteration.
type ConstantBackoff struct {
interval time.Duration
}

func NewConstantBackoff(interval time.Duration) ConstantBackoff {
return ConstantBackoff{interval: interval}
}

func (cb ConstantBackoff) Duration() time.Duration {
return cb.interval
}

func (cb ConstantBackoff) Reset() {
// Nothing to reset
}
28 changes: 28 additions & 0 deletions ecs-agent/utils/retry/constant_backoff_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

package retry

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func TestConstantBackoff(t *testing.T) {
backoff := NewConstantBackoff(2 * time.Second)
for i := 0; i < 10; i++ {
assert.Equal(t, 2*time.Second, backoff.Duration())
}
}

0 comments on commit 78a1bfa

Please sign in to comment.