faraday/script/server
Mislav Marohnić c2adfbf918 rewrite test script in bash
The HTTP server is now started in a subprocess, not a thread. Running it
in a Ruby thread had all sorts of problems on different Rubies, such as
random failures on Rubinius.

The new script also avoids starting the HTTP server if not needed, e.g.
if filtering arguments have been used to select only the non-adapter tests.

The script dumps the server log to stdout if any tests failed on Travis.

Avoids auto-starting the debugger because it blocks for input in Rubinius
https://travis-ci.org/lostisland/faraday/jobs/5956815
2013-04-04 01:33:36 +02:00

39 lines
979 B
Ruby
Executable File

#!/usr/bin/env ruby
old_verbose, $VERBOSE = $VERBOSE, nil
begin
require File.expand_path('../../test/live_server', __FILE__)
ensure
$VERBOSE = old_verbose
end
require 'webrick'
require 'fileutils'
port = 4000
if found = ARGV.index('-p')
port = ARGV[found + 1].to_i
end
FileUtils.mkdir_p('log')
log_io = File.open('log/test.log', 'w')
log_io.sync = true
webrick_opts = {
:Port => port, :Logger => WEBrick::Log::new(log_io),
:AccessLog => [[log_io, "[%{X-Faraday-Adapter}i] %m %U -> %s %b"]]
}
if ENV['SSL_KEY']
require 'openssl'
require 'webrick/https'
webrick_opts.update \
:SSLEnable => true,
:SSLPrivateKey => OpenSSL::PKey::RSA.new(File.read(ENV['SSL_KEY'])),
:SSLCertificate => OpenSSL::X509::Certificate.new(File.read(ENV['SSL_FILE'])),
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE
end
Rack::Handler::WEBrick.run(Faraday::LiveServer, webrick_opts) do |server|
trap(:INT) { server.stop }
trap(:TERM) { server.stop }
end