mirror of https://github.com/rails/rails
Do not run tests that have `ensure` instead of `skip`
Even if tests are "skipped" by `Minitest::Assertions#skip` `ensure` is executed because tests methods are Ruby methods. Adding conditions outside of the test methods, entire test methods are executed only when they are necessary.
This commit is contained in:
parent
fd7c773387
commit
1b736a8720
|
@ -423,38 +423,38 @@ module ActiveRecord
|
|||
rd.close
|
||||
end
|
||||
|
||||
def test_pool_from_any_process_for_uses_most_recent_spec
|
||||
skip unless current_adapter?(:SQLite3Adapter)
|
||||
if current_adapter?(:SQLite3Adapter)
|
||||
def test_pool_from_any_process_for_uses_most_recent_spec
|
||||
file = Tempfile.new "lol.sqlite3"
|
||||
|
||||
file = Tempfile.new "lol.sqlite3"
|
||||
rd, wr = IO.pipe
|
||||
rd.binmode
|
||||
wr.binmode
|
||||
|
||||
rd, wr = IO.pipe
|
||||
rd.binmode
|
||||
wr.binmode
|
||||
pid = fork do
|
||||
config_hash = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary").configuration_hash.merge(database: file.path)
|
||||
ActiveRecord::Base.establish_connection(config_hash)
|
||||
|
||||
pid = fork do
|
||||
config_hash = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary").configuration_hash.merge(database: file.path)
|
||||
ActiveRecord::Base.establish_connection(config_hash)
|
||||
pid2 = fork do
|
||||
wr.write ActiveRecord::Base.connection_db_config.database
|
||||
wr.close
|
||||
end
|
||||
|
||||
pid2 = fork do
|
||||
wr.write ActiveRecord::Base.connection_db_config.database
|
||||
wr.close
|
||||
Process.waitpid pid2
|
||||
end
|
||||
|
||||
Process.waitpid pid2
|
||||
end
|
||||
Process.waitpid pid
|
||||
|
||||
Process.waitpid pid
|
||||
wr.close
|
||||
|
||||
wr.close
|
||||
assert_equal file.path, rd.read
|
||||
|
||||
assert_equal file.path, rd.read
|
||||
|
||||
rd.close
|
||||
ensure
|
||||
if file
|
||||
file.close
|
||||
file.unlink
|
||||
rd.close
|
||||
ensure
|
||||
if file
|
||||
file.close
|
||||
file.unlink
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -565,37 +565,38 @@ class QueryCacheTest < ActiveRecord::TestCase
|
|||
}.call({})
|
||||
end
|
||||
|
||||
def test_clear_query_cache_is_called_on_all_connections
|
||||
skip "with in memory db, reading role won't be able to see database on writing role" if in_memory_db?
|
||||
|
||||
ActiveRecord::Base.connected_to(role: :reading) do
|
||||
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary")
|
||||
ActiveRecord::Base.establish_connection(db_config)
|
||||
end
|
||||
|
||||
mw = middleware { |env|
|
||||
# with in memory db, reading role won't be able to see database on writing role
|
||||
unless in_memory_db?
|
||||
def test_clear_query_cache_is_called_on_all_connections
|
||||
ActiveRecord::Base.connected_to(role: :reading) do
|
||||
@topic = Topic.first
|
||||
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary")
|
||||
ActiveRecord::Base.establish_connection(db_config)
|
||||
end
|
||||
|
||||
assert @topic
|
||||
mw = middleware { |env|
|
||||
ActiveRecord::Base.connected_to(role: :reading) do
|
||||
@topic = Topic.first
|
||||
end
|
||||
|
||||
ActiveRecord::Base.connected_to(role: :writing) do
|
||||
@topic.title = "Topic title"
|
||||
@topic.save!
|
||||
end
|
||||
assert @topic
|
||||
|
||||
assert_equal "Topic title", @topic.title
|
||||
ActiveRecord::Base.connected_to(role: :writing) do
|
||||
@topic.title = "Topic title"
|
||||
@topic.save!
|
||||
end
|
||||
|
||||
ActiveRecord::Base.connected_to(role: :reading) do
|
||||
@topic = Topic.first
|
||||
assert_equal "Topic title", @topic.title
|
||||
end
|
||||
}
|
||||
|
||||
mw.call({})
|
||||
ensure
|
||||
clean_up_connection_handler
|
||||
ActiveRecord::Base.connected_to(role: :reading) do
|
||||
@topic = Topic.first
|
||||
assert_equal "Topic title", @topic.title
|
||||
end
|
||||
}
|
||||
|
||||
mw.call({})
|
||||
ensure
|
||||
clean_up_connection_handler
|
||||
end
|
||||
end
|
||||
|
||||
test "query cache is enabled in threads with shared connection" do
|
||||
|
|
|
@ -18,8 +18,8 @@ module ConsoleHelpers
|
|||
|
||||
assert_includes output, expected, "#{expected.inspect} expected, but got:\n\n#{output}"
|
||||
end
|
||||
|
||||
def available_pty?
|
||||
defined?(PTY) && PTY.respond_to?(:open)
|
||||
end
|
||||
end
|
||||
|
||||
def available_pty?
|
||||
defined?(PTY) && PTY.respond_to?(:open)
|
||||
end
|
||||
|
|
|
@ -30,35 +30,31 @@ class Rails::Engine::CommandsTest < ActiveSupport::TestCase
|
|||
assert_equal "test", output.strip
|
||||
end
|
||||
|
||||
def test_console_command_work_inside_engine
|
||||
skip "PTY unavailable" unless available_pty?
|
||||
if available_pty?
|
||||
def test_console_command_work_inside_engine
|
||||
primary, replica = PTY.open
|
||||
cmd = "console --singleline"
|
||||
spawn_command(cmd, replica)
|
||||
assert_output(">", primary)
|
||||
ensure
|
||||
primary.puts "quit"
|
||||
end
|
||||
|
||||
primary, replica = PTY.open
|
||||
cmd = "console --singleline"
|
||||
spawn_command(cmd, replica)
|
||||
assert_output(">", primary)
|
||||
ensure
|
||||
primary.puts "quit"
|
||||
end
|
||||
def test_dbconsole_command_work_inside_engine
|
||||
primary, replica = PTY.open
|
||||
spawn_command("dbconsole", replica)
|
||||
assert_output("sqlite>", primary)
|
||||
ensure
|
||||
primary.puts ".exit"
|
||||
end
|
||||
|
||||
def test_dbconsole_command_work_inside_engine
|
||||
skip "PTY unavailable" unless available_pty?
|
||||
|
||||
primary, replica = PTY.open
|
||||
spawn_command("dbconsole", replica)
|
||||
assert_output("sqlite>", primary)
|
||||
ensure
|
||||
primary.puts ".exit"
|
||||
end
|
||||
|
||||
def test_server_command_work_inside_engine
|
||||
skip "PTY unavailable" unless available_pty?
|
||||
|
||||
primary, replica = PTY.open
|
||||
pid = spawn_command("server", replica)
|
||||
assert_output("Listening on", primary)
|
||||
ensure
|
||||
kill(pid)
|
||||
def test_server_command_work_inside_engine
|
||||
primary, replica = PTY.open
|
||||
pid = spawn_command("server", replica)
|
||||
assert_output("Listening on", primary)
|
||||
ensure
|
||||
kill(pid)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
Loading…
Reference in New Issue