Module: TestEngineer
- Defined in:
- lib/testengineer.rb,
lib/testengineer/version.rb
Constant Summary collapse
- VERSION =
"0.1.#{ENV['BUILD_NUMBER'] || 'dev'}"
Class Method Summary collapse
- .foreman ⇒ Object
- .start_stack ⇒ Object
- .stop_process(name) ⇒ Object
- .stop_stack ⇒ Object
- .wait_for_socket(host = 'localhost', port = nil) ⇒ Object
Class Method Details
.foreman ⇒ Object
6 7 8 |
# File 'lib/testengineer.rb', line 6 def self.foreman $foreman end |
.start_stack ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/testengineer.rb', line 54 def self.start_stack procfile = File.(Dir.pwd + '/Procfile') unless File.exists? procfile raise StandardError, 'Procfile does not exist!' end $foreman = ::Foreman::Engine.new(procfile, {}) Thread.new do foreman.start end end |
.stop_process(name) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/testengineer.rb', line 26 def self.stop_process(name) if foreman.nil? puts "Foreman hasn't been started, whoops" return end if name.nil? raise Exception, 'TestEngineer#stop_process cannot handle a nil process name' end procs = foreman.send(:running_processes) procs.each do |pid, p| parts = p.name.split('.') unless parts.first.start_with? name next end p.kill 'SIGTERM' ::Timeout.timeout(5) do begin Process.waitpid(pid) rescue Errno::ECHILD end end end # If we don't set @terminating to false, then the eventual invocation of # #terminate_gracefully will return immediately foreman.instance_variable_set(:@terminating, false) end |
.stop_stack ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/testengineer.rb', line 66 def self.stop_stack begin foreman.send(:terminate_gracefully) unless foreman.nil? rescue Errno::ECHILD => e # Children terminated before we could kill them, no big deal end foreman = nil end |
.wait_for_socket(host = 'localhost', port = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/testengineer.rb', line 10 def self.wait_for_socket(host='localhost', port=nil) return if port.nil? puts "Waiting for server at #{host}:#{port} to come online.." running = false while !running do sleep 0.2 begin TCPSocket.new(host, port) rescue Errno::ECONNREFUSED => e next end running = true end end |