Class: MockServer::BinaryLauncher::ServerHandle
- Inherits:
-
Object
- Object
- MockServer::BinaryLauncher::ServerHandle
- Defined in:
- lib/mockserver/binary_launcher.rb
Overview
Handle to a running MockServer process.
Instance Attribute Summary collapse
-
#launcher ⇒ String
readonly
Path to the launcher executable.
-
#pid ⇒ Integer
readonly
The process ID.
-
#port ⇒ Integer
readonly
The server port.
Instance Method Summary collapse
-
#initialize(pid:, port:, launcher:) ⇒ ServerHandle
constructor
A new instance of ServerHandle.
-
#running? ⇒ Boolean
True if the process is still running.
-
#stop(timeout: 10) ⇒ void
Stop the server by terminating the process.
Constructor Details
#initialize(pid:, port:, launcher:) ⇒ ServerHandle
Returns a new instance of ServerHandle.
588 589 590 591 592 |
# File 'lib/mockserver/binary_launcher.rb', line 588 def initialize(pid:, port:, launcher:) @pid = pid @port = port @launcher = launcher end |
Instance Attribute Details
#launcher ⇒ String (readonly)
Returns path to the launcher executable.
586 587 588 |
# File 'lib/mockserver/binary_launcher.rb', line 586 def launcher @launcher end |
#pid ⇒ Integer (readonly)
Returns the process ID.
580 581 582 |
# File 'lib/mockserver/binary_launcher.rb', line 580 def pid @pid end |
#port ⇒ Integer (readonly)
Returns the server port.
583 584 585 |
# File 'lib/mockserver/binary_launcher.rb', line 583 def port @port end |
Instance Method Details
#running? ⇒ Boolean
Returns true if the process is still running.
620 621 622 623 624 625 626 627 628 629 630 631 |
# File 'lib/mockserver/binary_launcher.rb', line 620 def running? return false unless @pid Process.kill(0, @pid) true rescue Errno::ESRCH # Process does not exist false rescue Errno::EPERM # Process exists but we lack permission to signal it — it IS running true end |
#stop(timeout: 10) ⇒ void
This method returns an undefined value.
Stop the server by terminating the process.
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 |
# File 'lib/mockserver/binary_launcher.rb', line 598 def stop(timeout: 10) return unless @pid begin Process.kill('TERM', @pid) deadline = Time.now + timeout loop do Process.waitpid(@pid, Process::WNOHANG) && break if Time.now > deadline Process.kill('KILL', @pid) Process.waitpid(@pid) break end sleep 0.1 end rescue Errno::ESRCH, Errno::ECHILD # Process already gone end @pid = nil end |