Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kcajmagic committed May 31, 2019
1 parent 1869131 commit a1a7147
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/caduceus/outboundSender.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ func (obs *CaduceusOutboundSender) send(secret, acceptType string, msg *wrp.Mess
// 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
return code < 200 || code > 299
},
}

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

0 comments on commit a1a7147

Please sign in to comment.