Module: HttpTest::Server
- Extended by:
- Server
- Included in:
- Server
- Defined in:
- lib/http-test/server.rb,
lib/http-test/server/port.rb
Defined Under Namespace
Modules: Port
Instance Method Summary collapse
-
#kill! ⇒ Object
Kills the current server process and checks that the port becomes unavailable.
- #start!(command) ⇒ Object
- #url_base ⇒ Object
Instance Method Details
#kill! ⇒ Object
Kills the current server process and checks that the port becomes unavailable.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/http-test/server.rb', line 7 def kill! return unless @pid Process.kill("TERM", @pid) Process.wait if @port && Port.available?(@port) STDERR.puts "Could not stop server" exit 1 end @port = nil @pid = nil end |
#start!(command) ⇒ 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 |
# File 'lib/http-test/server.rb', line 26 def start!(command) return if @started == command && @port kill! if @started started_at = Time.now @port = Port.choose @pid = fork do # Signal.trap("HUP") { STDERR.puts "Exiting web server"; exit } # # ... do some work ... ENV["RACK_ENV"] = "test" ENV["PORT"] = @port.to_s exec command end Port.wait(@port) secs = Time.now - started_at STDERR.puts "\n[http-test##{@pid}] test server '#{command}' running on #{url_base} after #{'%.3f secs' % secs}" @started = command end |
#url_base ⇒ Object
22 23 24 |
# File 'lib/http-test/server.rb', line 22 def url_base "http://127.0.0.1:#{@port}" end |