Skip to content

Commit b674f04

Browse files
committed
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.
1 parent b5c6f33 commit b674f04

File tree

1 file changed

+49
-46
lines changed

1 file changed

+49
-46
lines changed

activerecord/test/cases/query_cache_test.rb

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -95,66 +95,69 @@ def test_query_cache_is_applied_to_connections_in_all_handlers
9595
ActiveRecord::Base.connection_handlers = { writing: ActiveRecord::Base.default_connection_handler }
9696
end
9797

98-
def test_query_cache_with_multiple_handlers_and_forked_processes
99-
ActiveRecord::Base.connection_handlers = {
100-
writing: ActiveRecord::Base.default_connection_handler,
101-
reading: ActiveRecord::ConnectionAdapters::ConnectionHandler.new
102-
}
10398

104-
ActiveRecord::Base.connected_to(role: :reading) do
105-
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations["arunit"])
106-
end
99+
if Process.respond_to?(:fork) && !in_memory_db?
100+
def test_query_cache_with_multiple_handlers_and_forked_processes
101+
ActiveRecord::Base.connection_handlers = {
102+
writing: ActiveRecord::Base.default_connection_handler,
103+
reading: ActiveRecord::ConnectionAdapters::ConnectionHandler.new
104+
}
107105

108-
rd, wr = IO.pipe
109-
rd.binmode
110-
wr.binmode
106+
ActiveRecord::Base.connected_to(role: :reading) do
107+
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations["arunit"])
108+
end
111109

112-
pid = fork {
113-
rd.close
114-
status = 0
110+
rd, wr = IO.pipe
111+
rd.binmode
112+
wr.binmode
115113

116-
middleware { |env|
117-
begin
118-
assert_cache :clean
114+
pid = fork {
115+
rd.close
116+
status = 0
119117

120-
# first request dirties cache
121-
ActiveRecord::Base.connected_to(role: :reading) do
122-
Post.first
123-
assert_cache :dirty
124-
end
118+
middleware { |env|
119+
begin
120+
assert_cache :clean
125121

126-
# should clear the cache
127-
Post.create!(title: "a new post", body: "and a body")
122+
# first request dirties cache
123+
ActiveRecord::Base.connected_to(role: :reading) do
124+
Post.first
125+
assert_cache :dirty
126+
end
128127

129-
# fails because cache is still dirty
130-
ActiveRecord::Base.connected_to(role: :reading) do
131-
assert_cache :clean
132-
Post.first
128+
# should clear the cache
129+
Post.create!(title: "a new post", body: "and a body")
130+
131+
# fails because cache is still dirty
132+
ActiveRecord::Base.connected_to(role: :reading) do
133+
assert_cache :clean
134+
Post.first
135+
end
136+
137+
rescue Minitest::Assertion => e
138+
wr.write Marshal.dump e
139+
status = 1
133140
end
141+
}.call({})
134142

135-
rescue Minitest::Assertion => e
136-
wr.write Marshal.dump e
137-
status = 1
138-
end
139-
}.call({})
143+
wr.close
144+
exit!(status)
145+
}
140146

141147
wr.close
142-
exit!(status)
143-
}
144148

145-
wr.close
149+
Process.waitpid pid
150+
if !$?.success?
151+
raise Marshal.load(rd.read)
152+
else
153+
assert_predicate $?, :success?
154+
end
146155

147-
Process.waitpid pid
148-
if !$?.success?
149-
raise Marshal.load(rd.read)
150-
else
151-
assert_predicate $?, :success?
156+
rd.close
157+
ensure
158+
ActiveRecord::Base.connection_handlers = { writing: ActiveRecord::Base.default_connection_handler }
152159
end
153-
154-
rd.close
155-
ensure
156-
ActiveRecord::Base.connection_handlers = { writing: ActiveRecord::Base.default_connection_handler }
157-
end unless in_memory_db?
160+
end
158161

159162
def test_query_cache_across_threads
160163
with_temporary_connection_pool do

0 commit comments

Comments
 (0)