Class: Pact::Consumer::AppRegistration

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/pact/consumer/app_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

included, #logger

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

#appObject

Returns the value of attribute app.



103
104
105
# File 'lib/pact/consumer/app_manager.rb', line 103

def app
  @app
end

#pidObject

Returns the value of attribute pid.



104
105
106
# File 'lib/pact/consumer/app_manager.rb', line 104

def pid
  @pid
end

#portObject

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

Returns:

  • (Boolean)


130
131
132
# File 'lib/pact/consumer/app_manager.rb', line 130

def is_a_mock_service?
  app.is_a? MockService
end

#killObject



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

Returns:

  • (Boolean)


122
123
124
# File 'lib/pact/consumer/app_manager.rb', line 122

def not_spawned?
  !spawned?
end

#spawnObject



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

Returns:

  • (Boolean)


126
127
128
# File 'lib/pact/consumer/app_manager.rb', line 126

def spawned?
  self.pid != nil
end

#to_sObject



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_untilObject



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