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

Develop client/session separation #51

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f985ea7
Start performing a lot more error checking in Send()
bdotdub Dec 11, 2014
350d3e3
Pass the original notification through if we want it with Notificatio…
bdotdub Dec 11, 2014
7ce2c47
Undo NotificationResult api change
bdotdub Dec 12, 2014
f162ced
WIP
bdotdub Dec 16, 2014
d308f5e
Start simplifying the client internals
bdotdub Dec 16, 2014
64b0fc2
Update example
bdotdub Dec 16, 2014
4a7edba
Add connection resource locking
bdotdub Dec 23, 2014
e883640
Update notification test and remove old client test file
bdotdub Dec 23, 2014
0323581
WIP Convert Conn into an interface and make feedback test
bdotdub Jan 27, 2015
e2b7609
Lengthen timeouts for real tcp conn negotiation stuff
bdotdub Jan 29, 2015
abc584f
Add race detection
bdotdub Jan 29, 2015
1a7760c
Extend timeout
bdotdub Jan 29, 2015
2c85a0a
Start filling out client test
bdotdub Feb 13, 2015
9e1b5bb
Remove extraneous function
bdotdub Feb 13, 2015
4fa74c9
Adding more client tests
bdotdub Feb 13, 2015
df2b03d
Introduce session concept
bdotdub Feb 17, 2015
06384bf
Fix example
bdotdub Feb 17, 2015
d807d6b
Add more tests for client
bdotdub Feb 17, 2015
12a1dfa
Beginnings of a session test
bdotdub Feb 25, 2015
f87a8ee
Synchronize around the session state
bdotdub Feb 26, 2015
1456b9b
How do you even logic
bdotdub Mar 4, 2015
f841b7e
Clean up session states
bdotdub Mar 4, 2015
b8a8e42
Revise Travis CI config
nathany Apr 21, 2015
915e3b9
travis ci: notifications
nathany Apr 21, 2015
227fbfd
Merge pull request #39 from timehop/travis
nathany Apr 21, 2015
509f1d7
document exported identifiers
nathany Apr 23, 2015
89c02e1
ErrUnrecognizedErrorResponse
nathany Apr 23, 2015
c58921f
Merge pull request #41 from timehop/docs
nathany Apr 23, 2015
933c627
split out SetReadDeadline
nathany Apr 23, 2015
54aab15
keep NotificationResult
nathany May 15, 2015
3fa96ef
remove determineIdentifier (auto ID)
nathany May 20, 2015
0b6d1b0
move sent buffer code
nathany May 20, 2015
57489e7
find requeueable notifications on buffer
nathany May 20, 2015
55cf34e
catch json marshal errors
nathany May 20, 2015
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
17 changes: 12 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
sudo: false
language: go
go:
- 1.3
services:
- redis-server
- 1.4.2
before_script:
- go get github.com/onsi/ginkgo
- go get github.com/onsi/gomega
- go get code.google.com/p/go.tools/cmd/cover
- go get golang.org/x/tools/cmd/cover
- go install github.com/onsi/ginkgo/ginkgo
script: ginkgo -r --skipMeasurements --cover --trace
script: ginkgo -r --skipMeasurements --cover --trace --race
env:
global:
- PATH=$HOME/gopath/bin:$PATH

notifications:
email: false

branches:
only:
- master
- develop
37 changes: 37 additions & 0 deletions apns_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,45 @@ import (
. "github.com/onsi/gomega"

"testing"
"time"
)

type mockConn struct {
connect func() error
read func([]byte) (int, error)
setReadDeadline func(time.Time) error
}

func (m *mockConn) Connect() error {
if m.connect != nil {
return m.connect()
}

return nil
}

func (m *mockConn) Read(b []byte) (int, error) {
if m.read != nil {
return m.read(b)
}
return 0, nil
}

func (m *mockConn) Write([]byte) (int, error) {
return 0, nil
}

func (m *mockConn) Close() error {
return nil
}

func (m *mockConn) SetReadDeadline(t time.Time) error {
if m.setReadDeadline != nil {
return m.setReadDeadline(t)
}
return nil
}

func TestApns(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Apns Suite")
Expand Down
79 changes: 79 additions & 0 deletions buffer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package apns

import (
"container/list"
"sync"
)

// circular buffer of sent messages
// to retry if connection is dropped
type buffer struct {
size int
m sync.Mutex
*list.List
}

func newBuffer(size int) *buffer {
return &buffer{size, sync.Mutex{}, list.New()}
}

func (b *buffer) Add(v interface{}) *list.Element {
b.m.Lock()
defer b.m.Unlock()

e := b.PushBack(v)

if b.Len() > b.size {
b.Remove(b.Front())
}

return e
}

// NotificationResult associates an error from Apple to a notification.
type NotificationResult struct {
Notif Notification
Err Error
}

func (s NotificationResult) Error() string {
return s.Err.Error()
}

func (b *buffer) FindFailedNotification(e Error) NotificationResult {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't being used yet.

for cursor := b.Back(); cursor != nil; cursor = cursor.Prev() {
// Get serialized notification
n, _ := cursor.Value.(Notification)

// If the notification, move cursor after the trouble notification
if n.Identifier == e.Identifier {
return NotificationResult{n, e}
}
}
return NotificationResult{Notification{}, e}
}

// RequeueableNotifications returns good notifications sent after an error.
func (b *buffer) RequeueableNotifications(identifier uint32) []Notification {
notifs := []Notification{}

// Walk back to last known good notification and return the slice
var e *list.Element
for e = b.Front(); e != nil; e = e.Next() {
if n, ok := e.Value.(Notification); ok && n.Identifier == identifier {
break
}
}

// Start right after errored ID and get the rest of the list
for e = e.Next(); e != nil; e = e.Next() {
n, ok := e.Value.(Notification)
if !ok {
continue
}

notifs = append(notifs, n)
}

return notifs
}
11 changes: 11 additions & 0 deletions buffer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package apns

import (
. "github.com/onsi/ginkgo"
// . "github.com/onsi/gomega"
)

var _ = Describe("Session", func() {
Describe("RequeueableNotifications", func() {
})
})
Loading