mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Only test if we can use processes and it's not an in memory db
JRuby can't support processes, and in memory db can't support changing the handlers/connections during the test.
This commit is contained in:
parent
b5c6f33f0d
commit
b674f04756
1 changed files with 51 additions and 48 deletions
|
@ -95,66 +95,69 @@ class QueryCacheTest < ActiveRecord::TestCase
|
|||
ActiveRecord::Base.connection_handlers = { writing: ActiveRecord::Base.default_connection_handler }
|
||||
end
|
||||
|
||||
def test_query_cache_with_multiple_handlers_and_forked_processes
|
||||
ActiveRecord::Base.connection_handlers = {
|
||||
writing: ActiveRecord::Base.default_connection_handler,
|
||||
reading: ActiveRecord::ConnectionAdapters::ConnectionHandler.new
|
||||
}
|
||||
|
||||
ActiveRecord::Base.connected_to(role: :reading) do
|
||||
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations["arunit"])
|
||||
end
|
||||
if Process.respond_to?(:fork) && !in_memory_db?
|
||||
def test_query_cache_with_multiple_handlers_and_forked_processes
|
||||
ActiveRecord::Base.connection_handlers = {
|
||||
writing: ActiveRecord::Base.default_connection_handler,
|
||||
reading: ActiveRecord::ConnectionAdapters::ConnectionHandler.new
|
||||
}
|
||||
|
||||
rd, wr = IO.pipe
|
||||
rd.binmode
|
||||
wr.binmode
|
||||
ActiveRecord::Base.connected_to(role: :reading) do
|
||||
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations["arunit"])
|
||||
end
|
||||
|
||||
pid = fork {
|
||||
rd.close
|
||||
status = 0
|
||||
rd, wr = IO.pipe
|
||||
rd.binmode
|
||||
wr.binmode
|
||||
|
||||
middleware { |env|
|
||||
begin
|
||||
assert_cache :clean
|
||||
pid = fork {
|
||||
rd.close
|
||||
status = 0
|
||||
|
||||
# first request dirties cache
|
||||
ActiveRecord::Base.connected_to(role: :reading) do
|
||||
Post.first
|
||||
assert_cache :dirty
|
||||
end
|
||||
|
||||
# should clear the cache
|
||||
Post.create!(title: "a new post", body: "and a body")
|
||||
|
||||
# fails because cache is still dirty
|
||||
ActiveRecord::Base.connected_to(role: :reading) do
|
||||
middleware { |env|
|
||||
begin
|
||||
assert_cache :clean
|
||||
Post.first
|
||||
end
|
||||
|
||||
rescue Minitest::Assertion => e
|
||||
wr.write Marshal.dump e
|
||||
status = 1
|
||||
end
|
||||
}.call({})
|
||||
# first request dirties cache
|
||||
ActiveRecord::Base.connected_to(role: :reading) do
|
||||
Post.first
|
||||
assert_cache :dirty
|
||||
end
|
||||
|
||||
# should clear the cache
|
||||
Post.create!(title: "a new post", body: "and a body")
|
||||
|
||||
# fails because cache is still dirty
|
||||
ActiveRecord::Base.connected_to(role: :reading) do
|
||||
assert_cache :clean
|
||||
Post.first
|
||||
end
|
||||
|
||||
rescue Minitest::Assertion => e
|
||||
wr.write Marshal.dump e
|
||||
status = 1
|
||||
end
|
||||
}.call({})
|
||||
|
||||
wr.close
|
||||
exit!(status)
|
||||
}
|
||||
|
||||
wr.close
|
||||
exit!(status)
|
||||
}
|
||||
|
||||
wr.close
|
||||
Process.waitpid pid
|
||||
if !$?.success?
|
||||
raise Marshal.load(rd.read)
|
||||
else
|
||||
assert_predicate $?, :success?
|
||||
end
|
||||
|
||||
Process.waitpid pid
|
||||
if !$?.success?
|
||||
raise Marshal.load(rd.read)
|
||||
else
|
||||
assert_predicate $?, :success?
|
||||
rd.close
|
||||
ensure
|
||||
ActiveRecord::Base.connection_handlers = { writing: ActiveRecord::Base.default_connection_handler }
|
||||
end
|
||||
|
||||
rd.close
|
||||
ensure
|
||||
ActiveRecord::Base.connection_handlers = { writing: ActiveRecord::Base.default_connection_handler }
|
||||
end unless in_memory_db?
|
||||
end
|
||||
|
||||
def test_query_cache_across_threads
|
||||
with_temporary_connection_pool do
|
||||
|
|
Loading…
Reference in a new issue