Class: Cybertrain::Test::SentryReceiver
- Inherits:
-
HttpReceiver
- Object
- Receiver
- HttpReceiver
- Cybertrain::Test::SentryReceiver
- Defined in:
- cybertrain/test/sentry_receiver.rb
Overview
A receiver for the Sentry sender: accepts up to max envelopes (50
by default), one connection each, and answers each with status
(200: {"id":"..."}, as Sentry does; another status, such as 429,
tests a Sentry that refuses).
Instance Attribute Summary
Attributes inherited from Receiver
Instance Method Summary collapse
-
#dsn(project = "1", prefix = "") ⇒ String
A DSN that sends to this receiver, once started:
"http://public@127.0.0.1:<port><prefix>/<project>". -
#initialize(status: 200, max: 50, accept_window: 10.0) ⇒ SentryReceiver
constructor
A new instance of SentryReceiver.
-
#received_events(count, wait = 5.0) ⇒ Array<SentryEnvelope>
The envelopes that arrived, waiting at most
waitseconds forcountof them; fewer when the time ran out.
Methods inherited from HttpReceiver
#received_request, #received_requests, #respond_with, #url
Methods inherited from Receiver
Constructor Details
#initialize(status: 200, max: 50, accept_window: 10.0) ⇒ SentryReceiver
Returns a new instance of SentryReceiver.
179 180 181 182 |
# File 'cybertrain/test/sentry_receiver.rb', line 179 def initialize(status: 200, max: 50, accept_window: 10.0) super(status: status, headers: SentryReceiver.reply_headers, body: REPLY, max: max, accept_window: accept_window) end |
Instance Method Details
#dsn(project = "1", prefix = "") ⇒ String
A DSN that sends to this receiver, once started:
"http://public@127.0.0.1:<port><prefix>/<project>".
198 199 200 |
# File 'cybertrain/test/sentry_receiver.rb', line 198 def dsn(project = "1", prefix = "") "http://public@127.0.0.1:#{@port}#{prefix}/#{project}" end |
#received_events(count, wait = 5.0) ⇒ Array<SentryEnvelope>
The envelopes that arrived, waiting at most wait seconds for
count of them; fewer when the time ran out.
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'cybertrain/test/sentry_receiver.rb', line 208 def received_events(count, wait = 5.0) out = Array.new(0) { SentryEnvelope.new("", "", "", "") } received_requests(count, wait).each do |req| path = req.http_path auth = req.http_header("X-Sentry-Auth") type = req.http_header("Content-Type") body = req.http_body # The bytes as read are binary under CRuby (the preview); the # envelope is UTF-8 JSON text, so compare it as such (the # compiled String is the same bytes either way). unless body.encoding.to_s == "UTF-8" body = body.dup body.force_encoding("UTF-8") end out << SentryEnvelope.new(path, auth, type, body) end out end |