apns_gatling 0.1.5 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ded821dd7dfeeffc971eda81795497a104199b5
4
- data.tar.gz: 1eb94b36a9459b19bebfd949d3767d0b795b7f0b
3
+ metadata.gz: 683a9f97a25ddb358da1ded897fcf852dd394753
4
+ data.tar.gz: 7f5088c3f030e43c7530ff7f91d5ba75524d93a0
5
5
  SHA512:
6
- metadata.gz: d73fdc6ae1080d33b4a37e0f24b841961756ac111142e98fa4738e6d7c644885c5f7234b998e8518b788569137a2b930093f32957c7d55119048d2ec8ae90309
7
- data.tar.gz: 6c5fe03e2ccd0e302c6a1d7b664ad18da3d3ba6aac51def687f10e2b5640c2cef241a26aed50ee738162a736f4addcf0987b61160ffa909040010dd6fa1aab33
6
+ metadata.gz: c5e4721d36638633fedeb0c2d7b755316a57d3365f3af2568ee938d145ae7d4972fdbc78d3c831bb2812eb997ecf05000423f3632030946a507c3920070bae78
7
+ data.tar.gz: 9f9568bd6b3814d2c904f326f4aefe5122762aac79b3c0d20c2591332d87513ee7b5f36f1175a2ff0eb66fb9229dcdf4767b5708d49d940064e70cf7c1ff9770
@@ -22,4 +22,6 @@ client = ApnsGatling::Client.new team_id, auth_key_id, ecdsa_key, true
22
22
  end
23
23
  end
24
24
 
25
- client.join
25
+ loop {
26
+ sleep 1
27
+ }
@@ -15,6 +15,7 @@ module ApnsGatling
15
15
  @token_maker = Token.new(team_id, auth_key_id, ecdsa_key)
16
16
  @sandbox = sandbox
17
17
  @mutex = Mutex.new
18
+ @requests = {}
18
19
  @cv = ConditionVariable.new
19
20
  init_vars
20
21
  end
@@ -51,28 +52,62 @@ module ApnsGatling
51
52
  end
52
53
  end
53
54
 
55
+ def connection_error(e)
56
+ @mutex.synchronize do
57
+ @requests.values.map do | request |
58
+ block = request[:block]
59
+ response = request[:response]
60
+ if block && response
61
+ response.error_with("connection failed #{e}")
62
+ block.call response
63
+ end
64
+ end
65
+ @requests = {}
66
+ @connection = nil
67
+ end
68
+ end
69
+
54
70
  # push message
55
- def push(message)
71
+ def push(message, &block)
56
72
  request = Request.new(message, provider_token, host)
57
- response = Response.new
58
- ensure_socket_open
73
+ response = Response.new(message)
74
+ @mutex.synchronize do
75
+ @requests[request.id] = {block: block, response: response}
76
+ end
59
77
 
60
78
  begin
79
+ ensure_socket_open
61
80
  stream = connection.new_stream
81
+ rescue SocketError => e
82
+ response.error_with("create connection failed #{e}")
83
+ block.call response
84
+ return
85
+ rescue StreamLimitExceeded
86
+ response.error_with('stream limit exceeded')
87
+ block.call response
88
+ return
89
+ rescue ConnectionClosed
90
+ close
91
+ response.error_with('connection closed')
92
+ block.call response
93
+ return
62
94
  rescue StandardError => e
63
95
  close
64
- raise e
96
+ response.error_with("standard error #{e}")
97
+ block.call response
98
+ return
65
99
  end
66
100
 
67
101
  stream.on(:close) do
68
102
  @mutex.synchronize do
103
+ @requests.delete request.id
69
104
  @token_generated_at = 0 if response.status == '403' && response.error[:reason] == 'ExpiredProviderToken'
70
105
  if @blocking
71
106
  @blocking = false
72
107
  @cv.signal
73
108
  end
109
+ block.call response if block
74
110
  end
75
- yield response
76
111
  end
77
112
 
78
113
  stream.on(:headers) do |h|
@@ -112,12 +147,12 @@ module ApnsGatling
112
147
  socket_loop
113
148
  rescue EOFError
114
149
  init_vars
115
- raise SocketError.new('Socket was remotely closed')
150
+ connection_error(SocketError.new('Socket was remotely closed'))
116
151
  rescue Exception => e
117
152
  init_vars
118
- raise e
153
+ connection_error(e)
119
154
  end
120
- end.tap { |t| t.abort_on_exception = true }
155
+ end
121
156
  end
122
157
  end
123
158
 
@@ -169,6 +204,7 @@ module ApnsGatling
169
204
  def close
170
205
  exit_thread(@socket_thread)
171
206
  init_vars
207
+ @connection = nil
172
208
  end
173
209
 
174
210
  def exit_thread(thread)
@@ -1,9 +1,10 @@
1
1
  module ApnsGatling
2
2
  class Request
3
- attr_reader :host, :path, :auth_token, :headers, :data
3
+ attr_reader :id, :host, :path, :auth_token, :headers, :data
4
4
 
5
5
  def initialize(message, auth_token, host)
6
6
  path = "/3/device/#{message.token}"
7
+ @id = message.apns_id
7
8
  @path = path
8
9
  @auth_token = auth_token
9
10
  @headers = headers_from message, auth_token, host, path
@@ -4,10 +4,13 @@ module ApnsGatling
4
4
  class Response
5
5
  # See: https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html
6
6
  attr_accessor :headers, :data
7
+ attr_reader :message
7
8
 
8
- def initialize()
9
+ def initialize(message)
9
10
  @headers = {}
10
11
  @data = ''
12
+ @message = message
13
+ @internal_error = nil
11
14
  end
12
15
 
13
16
  def status
@@ -22,7 +25,12 @@ module ApnsGatling
22
25
  JSON.parse(@data) rescue @data
23
26
  end
24
27
 
28
+ def error_with(reason)
29
+ @internal_error = {reason: reason, 'apns-id': @message.apns_id, status: '0'}
30
+ end
31
+
25
32
  def error
33
+ return @internal_error if @internal_error
26
34
  if status != '200'
27
35
  e = {}
28
36
  e.merge!(status: @headers[':status']) if @headers[':status']
@@ -1,3 +1,3 @@
1
1
  module ApnsGatling
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apns_gatling
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cloud
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-25 00:00:00.000000000 Z
11
+ date: 2017-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http-2