Skip to content

Commit

Permalink
Merge pull request #139 from kcajmagic/retryLogic
Browse files Browse the repository at this point in the history
retry on non 2XX status codes
  • Loading branch information
schmidtw authored Jun 5, 2019
2 parents 52505f4 + 7b2600d commit f07deb3
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]
### Changed
-
- retry on non 2xx status codes

## [0.1.3] - 2019-02-27
### Changed
Expand Down
3 changes: 3 additions & 0 deletions src/caduceus/outboundSender.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@ func (obs *CaduceusOutboundSender) send(secret, acceptType string, msg *wrp.Mess
Counter: obs.deliveryRetryCounter.With("url", obs.id, "event", event),
// Always retry on failures up to the max count.
ShouldRetry: func(error) bool { return true },
ShouldRetryStatus: func(code int) bool {
return code < 200 || code > 299
},
}

// Send it
Expand Down
26 changes: 26 additions & 0 deletions src/caduceus/outboundSender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func simpleFactorySetup(trans *transport, cutOffPeriod time.Duration, matcher []
On("With", []string{"url", w.Config.URL, "code", "201"}).Return(fakeDC).
On("With", []string{"url", w.Config.URL, "code", "202"}).Return(fakeDC).
On("With", []string{"url", w.Config.URL, "code", "204"}).Return(fakeDC).
On("With", []string{"url", w.Config.URL, "code", "429", "event", "iot"}).Return(fakeDC).
On("With", []string{"url", w.Config.URL, "code", "failure"}).Return(fakeDC)
fakeDC.On("Add", 1.0).Return()
fakeDC.On("Add", 0.0).Return()
Expand Down Expand Up @@ -218,6 +219,31 @@ func TestSimpleRetry(t *testing.T) {
assert.Equal(int32(2), trans.i)
}

func Test429Retry(t *testing.T) {

assert := assert.New(t)

trans := &transport{}
trans.fn = func(req *http.Request, count int) (*http.Response, error) {
return &http.Response{StatusCode: 429}, nil
}

obs, err := simpleSetup(trans, time.Second, nil)

assert.NotNil(obs)
assert.Nil(err)

req := simpleRequest()
req.Source = "mac:112233445566"
req.TransactionUUID = "1234"
req.Destination = "event:iot"
obs.Queue(req)

obs.Shutdown(true)

assert.Equal(int32(2), trans.i)
}

// Simple test that covers the normal successful case with extra matchers
func TestSimpleWrpWithMatchers(t *testing.T) {

Expand Down
48 changes: 24 additions & 24 deletions src/glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/glide.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package: .
import:
- package: github.com/Comcast/webpa-common
version: ee36b7e7561c779aa65a66fbef35b46720486987
version: af2102421561cc50aa301642bb52a8376d834a61
- package: github.com/satori/go.uuid
version: f58768cc1a7a7e77a3bd49e98cdd21419399b6a3

0 comments on commit f07deb3

Please sign in to comment.