Class: Flare::Test::Node
- Inherits:
-
Object
- Object
- Flare::Test::Node
- Defined in:
- lib/flare/test/node.rb
Overview
Description
Instance Attribute Summary collapse
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#hostname_port ⇒ Object
readonly
Returns the value of attribute hostname_port.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #cont ⇒ Object
-
#initialize(hostname_port, pid) ⇒ Node
constructor
A new instance of Node.
- #open(&block) ⇒ Object
- #stop ⇒ Object
- #terminate ⇒ Object
Constructor Details
#initialize(hostname_port, pid) ⇒ Node
Returns a new instance of Node.
16 17 18 19 20 21 |
# File 'lib/flare/test/node.rb', line 16 def initialize(hostname_port, pid) @hostname_port = hostname_port @hostname, @port = hostname_port.split(':') @pid = pid @alive = true end |
Instance Attribute Details
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
59 60 61 |
# File 'lib/flare/test/node.rb', line 59 def hostname @hostname end |
#hostname_port ⇒ Object (readonly)
Returns the value of attribute hostname_port.
59 60 61 |
# File 'lib/flare/test/node.rb', line 59 def hostname_port @hostname_port end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
59 60 61 |
# File 'lib/flare/test/node.rb', line 59 def pid @pid end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
59 60 61 |
# File 'lib/flare/test/node.rb', line 59 def port @port end |
Instance Method Details
#cont ⇒ Object
41 42 43 |
# File 'lib/flare/test/node.rb', line 41 def cont Process.kill :CONT, @pid end |
#open(&block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/flare/test/node.rb', line 23 def open(&block) return nil unless @alive node = Flare::Tools::Node.open(@hostname, @port) return node if block.nil? ret = nil begin ret = block.call(node) rescue => e node.close raise e end ret end |
#stop ⇒ Object
37 38 39 |
# File 'lib/flare/test/node.rb', line 37 def stop Process.kill :STOP, @pid end |
#terminate ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/flare/test/node.rb', line 45 def terminate puts "killing... #{@pid}" begin Timeout.timeout(10) do Process.kill :TERM, @pid Process.waitpid @pid end rescue TimeoutError => e Process.kill :KILL, @pid Process.waitpid @pid end @alive = false end |