Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/pn 310 sms ttl #15

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1aec698
SMS check expired messages
bogh Mar 21, 2017
2445c37
Merge branch 'master' into feature/pn-310-sms-ttl
Mar 21, 2017
fd82c39
Merge branch 'master' into feature/pn-310-sms-ttl
bogh Mar 21, 2017
7845188
Simplify method according to PR
bogh Mar 21, 2017
3df9fea
Merge branch 'feature/pn-310-sms-ttl' of https://github.com/cosminren…
bogh Mar 21, 2017
fc351ad
Merge branch 'master' into feature/pn-310-sms-ttl
bogh Mar 21, 2017
613c7da
fix typo; add assert for metrics value
Mar 21, 2017
ab14544
added a Prometheus metric for expired messages; moved test
Mar 21, 2017
729b498
Change message `Expires` field to be a timestamp
bogh Mar 21, 2017
d0d4124
Merge branch 'master' into feature/pn-310-ttl-change-to-timestamp
Mar 21, 2017
d8428d3
Merge branch 'master' into feature/pn-310-ttl-change-to-timestamp
Mar 22, 2017
bfc87cf
Merge branch 'master' into feature/pn-310-sms-ttl
Mar 22, 2017
f4b2626
Merge branch 'master' of https://github.com/cosminrentea/gobbler into…
bogh Mar 27, 2017
8770557
Merge branch 'master' into feature/pn-310-sms-ttl
bogh Mar 27, 2017
73bdeee
Allow for empty expires field
bogh Mar 27, 2017
14342e4
Fix errors
bogh Mar 27, 2017
5344e5e
PR requested changes
bogh Mar 27, 2017
3994ae3
Read `Expires` message field from header for guble message
bogh Mar 27, 2017
ae6ac02
Set Expires field in rest client
bogh Mar 27, 2017
2ba024c
Merge branch 'feature/pn-310-sms-ttl' into feature/pn-310-ttl-for-mes…
bogh Mar 28, 2017
36d8439
Merge branch 'feature/pn-310-ttl-rest' into feature/pn-310-ttl-for-me…
bogh Mar 28, 2017
88d3cae
Merge branch 'feature/pn-310-sms-ttl' of https://github.com/cosminren…
bogh Mar 28, 2017
163654c
Merge branch 'feature/pn-310-sms-ttl' into feature/pn-310-ttl-for-mes…
bogh Mar 28, 2017
9f6dec6
Return error when message is expired
bogh Mar 28, 2017
da2ee2d
Merge branch 'feature/pn-310-ttl-for-messages' into feature/pn-310-sm…
bogh Mar 28, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion protocol/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (m *Message) SetFilter(key, value string) {
// Checks are made using `Expires` field timezone
func (m *Message) IsExpired() bool {
if m.Expires == nil {
return true
return false
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
return m.Expires != nil && m.Expires.Before(time.Now().In(m.Expires.Location()))
}
Expand Down
7 changes: 7 additions & 0 deletions protocol/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,10 @@ func TestMessage_IsExpired(t *testing.T) {
}

}

func TestMessage_IsExpired_WithNilExpires(t *testing.T) {
a := assert.New(t)

a.Equal(false, (&Message{}).IsExpired())

}
11 changes: 11 additions & 0 deletions server/sms/nexmo_sms_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@ func (ns *NexmoSender) Send(msg *protocol.Message) error {
return ErrRetryFailed
}

if msg.IsExpired() {
log.WithFields(log.Fields{
"ID": msg.ID,
"To": nexmoSMS.To,
"Expires": msg.Expires.Format(time.RFC3339),
"Created": time.Unix(msg.Time, 0).Format(time.RFC3339),
}).Info("Expired message received")
mTotalExpiredMessages.Add(1)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a prometheus equivalent for this in another PR

return nil
}

sendSms := func() (*NexmoMessageResponse, error) {
return ns.sendSms(nexmoSMS)
}
Expand Down
24 changes: 24 additions & 0 deletions server/sms/nexmo_sms_sender_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sms

import (
"net/http"
"testing"
"time"

Expand Down Expand Up @@ -35,3 +36,26 @@ func TestNexmoSender_SendWithError(t *testing.T) {
a.Error(err)
a.Equal(ErrRetryFailed, err)
}

func TestNexmoSender_SendExpiredMessage(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: I moved the test to sms_integration_test.go

a := assert.New(t)

port := createRandomPort(7000, 8000)
URL = "http://127.0.0.1" + port

sender := createNexmoSender(t)
// no request should be made in case the sms is expired
go dummyNexmoEndpointWithHandlerFunc(t, nil, port, func(t *testing.T, countCh chan bool) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
a.FailNow("Nexmo call not expected.")
}
})

msg := encodeProtocolMessage(t, 0)
expires := time.Now().Add(-1 * time.Hour)
msg.Expires = &expires

err := sender.Send(&msg)
time.Sleep(3 * timeInterval)
a.NoError(err)
}
4 changes: 3 additions & 1 deletion server/sms/sms_metrics.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package sms

import (
"github.com/cosminrentea/gobbler/server/metrics"
"time"

"github.com/cosminrentea/gobbler/server/metrics"
)

var (
Expand All @@ -11,6 +12,7 @@ var (
mTotalSendErrors = ns.NewInt("total_sent_message_errors")
mTotalResponseErrors = ns.NewInt("total_response_errors")
mTotalResponseInternalErrors = ns.NewInt("total_response_internal_errors")
mTotalExpiredMessages = ns.NewInt("total_expires_messages")
mMinute = ns.NewMap("minute")
mHour = ns.NewMap("hour")
mDay = ns.NewMap("day")
Expand Down