提交 287920ca 编写于 作者: M Matthew Draper

Respect ENV variables when finding DBs etc for the test suite

If they're not set we'll still fall back to localhost, but this makes it
possible to run the tests against a remote Postgres / Redis / whatever.
上级 44232b48
# frozen_string_literal: true
require "base64"
require "rake/testtask"
require "pathname"
require "open3"
......@@ -25,7 +26,8 @@ namespace :test do
end
task :integration do
system("yarn test") || raise("Failures")
system(Hash[*Base64.decode64(ENV.fetch("ENCODED", "")).split(/[ =]/)], "yarn", "test")
exit($?.exitstatus) unless $?.success?
end
end
......
......@@ -11,7 +11,11 @@ class RedisAdapterTest < ActionCable::TestCase
include ChannelPrefixTest
def cable_config
{ adapter: "redis", driver: "ruby" }
{ adapter: "redis", driver: "ruby" }.tap do |x|
if host = URI(ENV["REDIS_URL"] || "").hostname
x[:host] = host
end
end
end
end
......@@ -25,7 +29,7 @@ class RedisAdapterTest::AlternateConfiguration < RedisAdapterTest
def cable_config
alt_cable_config = super.dup
alt_cable_config.delete(:url)
alt_cable_config.merge(host: "127.0.0.1", port: 6379, db: 12)
alt_cable_config.merge(host: URI(ENV["REDIS_URL"] || "").hostname || "127.0.0.1", port: 6379, db: 12)
end
end
......
......@@ -38,8 +38,9 @@ def call_reset_session
begin
require "dalli"
ss = Dalli::Client.new("localhost:11211").stats
raise Dalli::DalliError unless ss["localhost:11211"]
servers = ENV["MEMCACHE_SERVERS"] || "localhost:11211"
ss = Dalli::Client.new(servers).stats
raise Dalli::DalliError unless ss[servers]
def test_setting_and_getting_session_value
with_test_route_set do
......@@ -195,7 +196,9 @@ def with_test_route_set
end
@app = self.class.build_app(set) do |middleware|
middleware.use ActionDispatch::Session::MemCacheStore, key: "_session_id", namespace: "mem_cache_store_test:#{SecureRandom.hex(10)}"
middleware.use ActionDispatch::Session::MemCacheStore,
key: "_session_id", namespace: "mem_cache_store_test:#{SecureRandom.hex(10)}",
memcache_server: ENV["MEMCACHE_SERVERS"] || "localhost:11211"
middleware.delete ActionDispatch::ShowExceptions
end
......
......@@ -31,9 +31,26 @@ namespace :test do
desc "Run tests for rails-ujs"
task :ujs do
system("npm run lint")
exit $?.exitstatus unless $?.success?
begin
listen_host = "localhost"
listen_port = "4567"
runner_command = %w(ruby ../ci/qunit-selenium-runner.rb)
if ENV["SELENIUM_DRIVER_URL"]
require "socket"
runner_command += %W(http://#{Socket.gethostname}:#{listen_port}/ #{ENV["SELENIUM_DRIVER_URL"]})
listen_host = "0.0.0.0"
else
runner_command += %W(http://localhost:#{listen_port}/)
end
Dir.mkdir("log")
pid = spawn("bundle exec rackup test/ujs/config.ru -p 4567 -s puma > log/test.log 2>&1", pgroup: true)
pid = File.open("log/test.log", "w") do |f|
spawn(*%W(rackup test/ujs/config.ru -o #{listen_host} -p #{listen_port} -s puma), out: f, err: f, pgroup: true)
end
start_time = Time.now
......@@ -41,12 +58,16 @@ namespace :test do
break if system("lsof -i :4567", 1 => File::NULL)
if Time.now - start_time > 5
puts "Timed out after 5 seconds"
puts "Failed to start puma after 5 seconds"
puts
puts File.read("log/test.log")
exit 1
end
sleep 0.2
end
system("npm run lint && bundle exec ruby ../ci/qunit-selenium-runner.rb http://localhost:4567/")
system(*runner_command)
status = $?.exitstatus
ensure
Process.kill("KILL", -pid) if pid
......
......@@ -23,6 +23,7 @@ class Server < Rails::Application
config.public_file_server.enabled = true
config.logger = Logger.new(STDOUT)
config.log_level = :error
config.hosts << proc { true }
config.content_security_policy do |policy|
policy.default_src :self, :https
......
......@@ -4,6 +4,7 @@ module BackburnerJobsManager
def setup
ActiveJob::Base.queue_adapter = :backburner
Backburner.configure do |config|
config.beanstalk_url = ENV["BEANSTALK_URL"] if ENV["BEANSTALK_URL"]
config.logger = Rails.logger
end
unless can_run?
......
......@@ -3,7 +3,7 @@
module ResqueJobsManager
def setup
ActiveJob::Base.queue_adapter = :resque
Resque.redis = Redis::Namespace.new "active_jobs_int_test", redis: Redis.new(url: "redis://127.0.0.1:6379/12", thread_safe: true)
Resque.redis = Redis::Namespace.new "active_jobs_int_test", redis: Redis.new(url: ENV["REDIS_URL"] || "redis://127.0.0.1:6379/12", thread_safe: true)
Resque.logger = Rails.logger
unless can_run?
puts "Cannot run integration tests for resque. To be able to run integration tests for resque you need to install and start redis.\n"
......
......@@ -7,7 +7,7 @@ module SneakersJobsManager
def setup
ActiveJob::Base.queue_adapter = :sneakers
Sneakers.configure heartbeat: 2,
amqp: "amqp://guest:guest@localhost:5672",
amqp: ENV["RABBITMQ_URL"] || "amqp://guest:guest@localhost:5672",
vhost: "/",
exchange: "active_jobs_sneakers_int_test",
exchange_type: :direct,
......
......@@ -89,18 +89,23 @@ end
namespace :db do
namespace :mysql do
connection_arguments = lambda do |connection_name|
config = ARTest.config["connections"]["mysql2"][connection_name]
["--user=#{config["username"]}", "--password=#{config["password"]}", ("--host=#{config["host"]}" if config["host"])].join(" ")
end
desc "Build the MySQL test databases"
task :build do
config = ARTest.config["connections"]["mysql2"]
%x( mysql --user=#{config["arunit"]["username"]} --password=#{config["arunit"]["password"]} -e "create DATABASE #{config["arunit"]["database"]} DEFAULT CHARACTER SET utf8mb4" )
%x( mysql --user=#{config["arunit2"]["username"]} --password=#{config["arunit2"]["password"]} -e "create DATABASE #{config["arunit2"]["database"]} DEFAULT CHARACTER SET utf8mb4" )
%x( mysql #{connection_arguments["arunit"]} -e "create DATABASE #{config["arunit"]["database"]} DEFAULT CHARACTER SET utf8mb4" )
%x( mysql #{connection_arguments["arunit2"]} -e "create DATABASE #{config["arunit2"]["database"]} DEFAULT CHARACTER SET utf8mb4" )
end
desc "Drop the MySQL test databases"
task :drop do
config = ARTest.config["connections"]["mysql2"]
%x( mysqladmin --user=#{config["arunit"]["username"]} --password=#{config["arunit"]["password"]} -f drop #{config["arunit"]["database"]} )
%x( mysqladmin --user=#{config["arunit2"]["username"]} --password=#{config["arunit2"]["password"]} -f drop #{config["arunit2"]["database"]} )
%x( mysqladmin #{connection_arguments["arunit"]} -f drop #{config["arunit"]["database"]} )
%x( mysqladmin #{connection_arguments["arunit2"]} -f drop #{config["arunit2"]["database"]} )
end
desc "Rebuild the MySQL test databases"
......
......@@ -54,10 +54,16 @@ connections:
username: rails
encoding: utf8mb4
collation: utf8mb4_unicode_ci
<% if ENV['MYSQL_HOST'] %>
host: <%= ENV['MYSQL_HOST'] %>
<% end %>
arunit2:
username: rails
encoding: utf8mb4
collation: utf8mb4_general_ci
<% if ENV['MYSQL_HOST'] %>
host: <%= ENV['MYSQL_HOST'] %>
<% end %>
oracle:
arunit:
......
......@@ -204,7 +204,7 @@ def emulating_latency
class RedisDistributedConnectionPoolBehaviourTest < ConnectionPoolBehaviourTest
private
def store_options
{ url: %w[ redis://localhost:6379/0 redis://localhost:6379/0 ] }
{ url: [ENV["REDIS_URL"] || "redis://localhost:6379/0"] * 2 }
end
end
......
# frozen_string_literal: true
require "qunit/selenium/test_runner"
require "chromedriver-helper"
driver_options = Selenium::WebDriver::Chrome::Options.new
driver_options.add_argument("--headless")
driver_options.add_argument("--disable-gpu")
driver_options.add_argument("--no-sandbox")
if ARGV[1]
driver = ::Selenium::WebDriver.for(:remote, url: ARGV[1], desired_capabilities: :chrome)
else
require "chromedriver-helper"
driver_options = Selenium::WebDriver::Chrome::Options.new
driver_options.add_argument("--headless")
driver_options.add_argument("--disable-gpu")
driver_options.add_argument("--no-sandbox")
driver = ::Selenium::WebDriver.for(:chrome, options: driver_options)
end
driver = ::Selenium::WebDriver.for(:chrome, options: driver_options)
result = QUnit::Selenium::TestRunner.new(driver).open(ARGV[0], timeout: 60)
driver.quit
......
......@@ -88,4 +88,15 @@ HELP
end
end
task :test do
templates = Dir.glob("bug_report_templates/*.rb")
counter = templates.count do |file|
puts "--- Running #{file}"
Bundler.clean_system(Gem.ruby, "-w", file) ||
puts("+++ 💥 FAILED (exit #{$?.exitstatus})")
end
puts "+++ #{counter} / #{templates.size} templates executed successfully"
exit 1 if counter < templates.size
end
task default: "guides:help"
......@@ -36,10 +36,20 @@ namespace :test do
dirs = (ENV["TEST_DIR"] || ENV["TEST_DIRS"] || "**").split(",")
test_options = ENV["TESTOPTS"].to_s.split(/[\s]+/)
test_files = dirs.map { |dir| "test/#{dir}/*_test.rb" }
Dir[*test_files].each do |file|
next true if file.start_with?("test/fixtures/")
test_patterns = dirs.map { |dir| "test/#{dir}/*_test.rb" }
test_files = Dir[*test_patterns].select do |file|
!file.start_with?("test/fixtures/")
end.sort
if ENV["BUILDKITE_PARALLEL_JOB_COUNT"]
n = ENV["BUILDKITE_PARALLEL_JOB"].to_i
m = ENV["BUILDKITE_PARALLEL_JOB_COUNT"].to_i
test_files = test_files.each_slice(m).map { |slice| slice[n] }.compact
end
test_files.each do |file|
puts "--- #{file}"
fake_command = Shellwords.join([
FileUtils::RUBY,
"-w",
......@@ -59,10 +69,13 @@ namespace :test do
unless $?.success?
failing_files << file
puts "^^^ +++"
end
end
puts "--- All tests completed"
unless failing_files.empty?
puts "^^^ +++"
puts
puts "Failed in:"
failing_files.each do |file|
......@@ -70,7 +83,7 @@ namespace :test do
end
puts
raise "Failure in isolated test runner"
exit 1
end
end
end
......
......@@ -93,6 +93,8 @@ def with_database_existing
def with_bad_permissions
Dir.chdir(app_path) do
skip "Can't avoid permissions as root" if Process.uid.zero?
set_database_url
FileUtils.chmod("-w", "db")
yield
......
......@@ -29,16 +29,18 @@ def teardown
primary, replica = PTY.open
pid = nil
begin
pid = Process.spawn("#{app_path}/bin/rails server -P tmp/dummy.pid", in: replica, out: replica, err: replica)
assert_output("Listening", primary)
rails("restart")
assert_output("Restarting", primary)
assert_output("Inherited", primary)
ensure
kill(pid) if pid
Bundler.with_original_env do
begin
pid = Process.spawn("bin/rails server -P tmp/dummy.pid", chdir: app_path, in: replica, out: replica, err: replica)
assert_output("Listening", primary)
rails("restart")
assert_output("Restarting", primary)
assert_output("Inherited", primary)
ensure
kill(pid) if pid
end
end
end
......
......@@ -19,6 +19,7 @@ class MyApp < Rails::Application
config.session_store :cookie_store, key: "_myapp_session"
config.active_support.deprecation = :log
config.eager_load = false
config.hosts << proc { true }
end
Rails.application.initialize!
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册