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.
618 619 620 621 622 |
# File 'lib/mockserver/binary_launcher.rb', line 618 def initialize(pid:, port:, launcher:) @pid = pid @port = port @launcher = launcher end |
Instance Attribute Details
#launcher ⇒ String (readonly)
Returns path to the launcher executable.
616 617 618 |
# File 'lib/mockserver/binary_launcher.rb', line 616 def launcher @launcher end |
#pid ⇒ Integer (readonly)
Returns the process ID.
610 611 612 |
# File 'lib/mockserver/binary_launcher.rb', line 610 def pid @pid end |
#port ⇒ Integer (readonly)
Returns the server port.
613 614 615 |
# File 'lib/mockserver/binary_launcher.rb', line 613 def port @port end |
Instance Method Details
#running? ⇒ Boolean
Returns true if the process is still running.
650 651 652 653 654 655 656 657 658 659 660 661 |
# File 'lib/mockserver/binary_launcher.rb', line 650 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.
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 |
# File 'lib/mockserver/binary_launcher.rb', line 628 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 |