Module: TestEngineer
- Defined in:
- lib/testengineer.rb,
lib/testengineer/version.rb
Constant Summary collapse
- VERSION =
"0.2.#{ENV['BUILD_NUMBER'] || 'dev'}"
Class Attribute Summary collapse
-
.procfile ⇒ Object
Returns the value of attribute procfile.
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 Attribute Details
.procfile ⇒ Object
Returns the value of attribute procfile.
7 8 9 |
# File 'lib/testengineer.rb', line 7 def procfile @procfile end |
Class Method Details
.foreman ⇒ Object
12 13 14 |
# File 'lib/testengineer.rb', line 12 def self.foreman $foreman end |
.start_stack ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/testengineer.rb', line 60 def self.start_stack procfile = File.(self.procfile, Dir.pwd) unless File.exists? procfile raise StandardError, 'Procfile does not exist!' end $foreman = ::Foreman::Engine::CLI.new foreman.load_procfile(procfile) Thread.new do foreman.start end end |
.stop_process(name) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/testengineer.rb', line 32 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
73 74 75 76 77 78 79 80 |
# File 'lib/testengineer.rb', line 73 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
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/testengineer.rb', line 16 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 |