aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2019-02-06 01:20:06 +1030
committerMatthew Draper <matthew@trebex.net>2019-02-06 01:20:06 +1030
commit287920ca7d06c8f51198ec750d65ba703835b257 (patch)
treefa38811f965fa873d02bc7df3317583ada076ff1
parent44232b485485634d681c60868c619323f882e59f (diff)
downloadrails-287920ca7d06c8f51198ec750d65ba703835b257.tar.gz
rails-287920ca7d06c8f51198ec750d65ba703835b257.tar.bz2
rails-287920ca7d06c8f51198ec750d65ba703835b257.zip
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.
-rw-r--r--actioncable/Rakefile4
-rw-r--r--actioncable/test/subscription_adapter/redis_test.rb8
-rw-r--r--actionpack/test/dispatch/session/mem_cache_store_test.rb9
-rw-r--r--actionview/Rakefile27
-rw-r--r--actionview/test/ujs/server.rb1
-rw-r--r--activejob/test/support/integration/adapters/backburner.rb1
-rw-r--r--activejob/test/support/integration/adapters/resque.rb2
-rw-r--r--activejob/test/support/integration/adapters/sneakers.rb2
-rw-r--r--activerecord/Rakefile13
-rw-r--r--activerecord/test/config.example.yml6
-rw-r--r--activesupport/test/cache/stores/redis_cache_store_test.rb2
-rw-r--r--ci/qunit-selenium-runner.rb18
-rw-r--r--guides/Rakefile11
-rw-r--r--railties/Rakefile21
-rw-r--r--railties/test/application/rake/dbs_test.rb2
-rw-r--r--railties/test/application/server_test.rb22
-rw-r--r--railties/test/application/url_generation_test.rb1
17 files changed, 114 insertions, 36 deletions
diff --git a/actioncable/Rakefile b/actioncable/Rakefile
index 35de50f05a..121037844d 100644
--- a/actioncable/Rakefile
+++ b/actioncable/Rakefile
@@ -1,5 +1,6 @@
# 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
diff --git a/actioncable/test/subscription_adapter/redis_test.rb b/actioncable/test/subscription_adapter/redis_test.rb
index ac2d8ef724..35840a4036 100644
--- a/actioncable/test/subscription_adapter/redis_test.rb
+++ b/actioncable/test/subscription_adapter/redis_test.rb
@@ -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
diff --git a/actionpack/test/dispatch/session/mem_cache_store_test.rb b/actionpack/test/dispatch/session/mem_cache_store_test.rb
index 9b51ee1cad..ac685a7dca 100644
--- a/actionpack/test/dispatch/session/mem_cache_store_test.rb
+++ b/actionpack/test/dispatch/session/mem_cache_store_test.rb
@@ -38,8 +38,9 @@ class MemCacheStoreTest < ActionDispatch::IntegrationTest
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 @@ class MemCacheStoreTest < ActionDispatch::IntegrationTest
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
diff --git a/actionview/Rakefile b/actionview/Rakefile
index 7851a2b6bf..237e458b6f 100644
--- a/actionview/Rakefile
+++ b/actionview/Rakefile
@@ -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
diff --git a/actionview/test/ujs/server.rb b/actionview/test/ujs/server.rb
index 56f436c8b8..d7a6271587 100644
--- a/actionview/test/ujs/server.rb
+++ b/actionview/test/ujs/server.rb
@@ -23,6 +23,7 @@ module UJS
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
diff --git a/activejob/test/support/integration/adapters/backburner.rb b/activejob/test/support/integration/adapters/backburner.rb
index 1163ae8178..0c248dda01 100644
--- a/activejob/test/support/integration/adapters/backburner.rb
+++ b/activejob/test/support/integration/adapters/backburner.rb
@@ -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?
diff --git a/activejob/test/support/integration/adapters/resque.rb b/activejob/test/support/integration/adapters/resque.rb
index 2ed8302277..cd129e72b2 100644
--- a/activejob/test/support/integration/adapters/resque.rb
+++ b/activejob/test/support/integration/adapters/resque.rb
@@ -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"
diff --git a/activejob/test/support/integration/adapters/sneakers.rb b/activejob/test/support/integration/adapters/sneakers.rb
index eb8d4cc2d5..89dc61ca28 100644
--- a/activejob/test/support/integration/adapters/sneakers.rb
+++ b/activejob/test/support/integration/adapters/sneakers.rb
@@ -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,
diff --git a/activerecord/Rakefile b/activerecord/Rakefile
index 013e81c959..9824787658 100644
--- a/activerecord/Rakefile
+++ b/activerecord/Rakefile
@@ -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"
diff --git a/activerecord/test/config.example.yml b/activerecord/test/config.example.yml
index 33962f9e5e..f5e3ac3c19 100644
--- a/activerecord/test/config.example.yml
+++ b/activerecord/test/config.example.yml
@@ -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:
diff --git a/activesupport/test/cache/stores/redis_cache_store_test.rb b/activesupport/test/cache/stores/redis_cache_store_test.rb
index 305a2c184d..273b196458 100644
--- a/activesupport/test/cache/stores/redis_cache_store_test.rb
+++ b/activesupport/test/cache/stores/redis_cache_store_test.rb
@@ -204,7 +204,7 @@ module ActiveSupport::Cache::RedisCacheStoreTests
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
diff --git a/ci/qunit-selenium-runner.rb b/ci/qunit-selenium-runner.rb
index 132b3d17eb..1df6aedb36 100644
--- a/ci/qunit-selenium-runner.rb
+++ b/ci/qunit-selenium-runner.rb
@@ -1,14 +1,20 @@
# 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
diff --git a/guides/Rakefile b/guides/Rakefile
index 4116e6f9cc..b7425f6de4 100644
--- a/guides/Rakefile
+++ b/guides/Rakefile
@@ -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"
diff --git a/railties/Rakefile b/railties/Rakefile
index 445f6217b3..1c4725e2d6 100644
--- a/railties/Rakefile
+++ b/railties/Rakefile
@@ -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
diff --git a/railties/test/application/rake/dbs_test.rb b/railties/test/application/rake/dbs_test.rb
index 84ac2f057e..5879949b61 100644
--- a/railties/test/application/rake/dbs_test.rb
+++ b/railties/test/application/rake/dbs_test.rb
@@ -93,6 +93,8 @@ module ApplicationTests
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
diff --git a/railties/test/application/server_test.rb b/railties/test/application/server_test.rb
index f4bd09903a..5b8aab08d5 100644
--- a/railties/test/application/server_test.rb
+++ b/railties/test/application/server_test.rb
@@ -29,16 +29,18 @@ module ApplicationTests
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
diff --git a/railties/test/application/url_generation_test.rb b/railties/test/application/url_generation_test.rb
index f22b9fda3d..6bcc0b0acb 100644
--- a/railties/test/application/url_generation_test.rb
+++ b/railties/test/application/url_generation_test.rb
@@ -19,6 +19,7 @@ module ApplicationTests
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!