Class: Pact::Consumer::AppRegistration
- Inherits:
-
Object
- Object
- Pact::Consumer::AppRegistration
- Includes:
- Logging
- Defined in:
- lib/pact/consumer/app_manager.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(opts) ⇒ AppRegistration
constructor
A new instance of AppRegistration.
- #is_a_mock_service? ⇒ Boolean
- #kill ⇒ Object
- #not_spawned? ⇒ Boolean
- #spawn ⇒ Object
- #spawned? ⇒ Boolean
- #to_s ⇒ Object
- #wait_until ⇒ Object
Methods included from Logging
Constructor Details
#initialize(opts) ⇒ AppRegistration
Returns a new instance of AppRegistration.
106 107 108 109 110 111 |
# File 'lib/pact/consumer/app_manager.rb', line 106 def initialize opts @max_wait = 10 @port = opts[:port] @pid = opts[:pid] @app = opts[:app] end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
103 104 105 |
# File 'lib/pact/consumer/app_manager.rb', line 103 def app @app end |
#pid ⇒ Object
Returns the value of attribute pid.
104 105 106 |
# File 'lib/pact/consumer/app_manager.rb', line 104 def pid @pid end |
#port ⇒ Object
Returns the value of attribute port.
102 103 104 |
# File 'lib/pact/consumer/app_manager.rb', line 102 def port @port end |
Instance Method Details
#is_a_mock_service? ⇒ Boolean
130 131 132 |
# File 'lib/pact/consumer/app_manager.rb', line 130 def is_a_mock_service? app.is_a? MockService end |
#kill ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/pact/consumer/app_manager.rb', line 113 def kill # TODO: need to work out how to kill # logger.info "Killing #{self}" # Process.kill(9, pid) # Process.wait(pid) # self.pid = nil self.pid = nil end |
#not_spawned? ⇒ Boolean
122 123 124 |
# File 'lib/pact/consumer/app_manager.rb', line 122 def not_spawned? !spawned? end |
#spawn ⇒ Object
138 139 140 141 142 143 |
# File 'lib/pact/consumer/app_manager.rb', line 138 def spawn logger.info "Starting app #{self}..." Pact::Server.new(app, port).boot self.pid = 'unknown' logger.info "Started with pid #{pid}" end |
#spawned? ⇒ Boolean
126 127 128 |
# File 'lib/pact/consumer/app_manager.rb', line 126 def spawned? self.pid != nil end |
#to_s ⇒ Object
134 135 136 |
# File 'lib/pact/consumer/app_manager.rb', line 134 def to_s "#{app} on port #{port}" + (@pid ? " with pid #{pid}" : "") end |
#wait_until ⇒ Object
145 146 147 148 149 150 151 152 153 154 |
# File 'lib/pact/consumer/app_manager.rb', line 145 def wait_until waited = 0 wait_time = 0.1 while waited < @max_wait do break if yield sleep wait_time waited += wait_time raise "Waited longer than #{@max_wait} seconds" if waited >= @max_wait end end |