Class: Straycall::Reporter::ThreadReporter
- Inherits:
-
Object
- Object
- Straycall::Reporter::ThreadReporter
- Defined in:
- lib/straycall/reporter/thread_reporter.rb
Instance Attribute Summary collapse
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
-
#initialize(socket) ⇒ ThreadReporter
constructor
A new instance of ThreadReporter.
- #notify_example(example) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #violation? ⇒ Boolean
Constructor Details
#initialize(socket) ⇒ ThreadReporter
Returns a new instance of ThreadReporter.
10 11 12 13 14 15 |
# File 'lib/straycall/reporter/thread_reporter.rb', line 10 def initialize(socket) @socket = socket @reader = Protocol::Reader.new(socket) @write_mutex = Mutex.new @violation = false end |
Instance Attribute Details
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
8 9 10 |
# File 'lib/straycall/reporter/thread_reporter.rb', line 8 def thread @thread end |
Instance Method Details
#notify_example(example) ⇒ Object
27 28 29 |
# File 'lib/straycall/reporter/thread_reporter.rb', line 27 def notify_example(example) @example = Protocol.example(example) end |
#start ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/straycall/reporter/thread_reporter.rb', line 17 def start return self unless RUBY_ENGINE == "ruby" && Thread.current.respond_to?(:native_thread_id) ready = Queue.new @thread = Thread.new { ready << true; run } @thread.name = "straycall-reporter" if @thread.respond_to?(:name=) ready.pop self end |
#stop ⇒ Object
40 41 42 43 |
# File 'lib/straycall/reporter/thread_reporter.rb', line 40 def stop @socket.close unless @socket.closed? @thread&.join(0.2) end |
#violation? ⇒ Boolean
31 32 33 34 35 36 37 38 |
# File 'lib/straycall/reporter/thread_reporter.rb', line 31 def violation? return true if @violation pending = @socket.recv_nonblock(Protocol::Reader::LIMIT, Socket::MSG_PEEK, exception: false) pending.is_a?(String) && pending.match?(/(?:\A|\n)VIOLATION\n/) rescue IOError, SystemCallError false end |