mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make the isolated tests run on JRuby
As there is no forking on JRuby, we need to spawn sub-processes to make the tests run in isolation. Previously, we were defining globally env variables and running the test file through backticks and delete these variables once the test ran. Now, we simply rely on IO.popen as this is cross-platform and the env variables are available during the child-process execution only so there are no race conditions. [Ben Browning & Robin Dupret]
This commit is contained in:
parent
0e9a705966
commit
3136388e55
1 changed files with 15 additions and 5 deletions
|
@ -70,14 +70,24 @@ module ActiveSupport
|
||||||
exit!
|
exit!
|
||||||
else
|
else
|
||||||
Tempfile.open("isolation") do |tmpfile|
|
Tempfile.open("isolation") do |tmpfile|
|
||||||
ENV["ISOLATION_TEST"] = self.class.name
|
env = {
|
||||||
ENV["ISOLATION_OUTPUT"] = tmpfile.path
|
ISOLATION_TEST: self.class.name,
|
||||||
|
ISOLATION_OUTPUT: tmpfile.path
|
||||||
|
}
|
||||||
|
|
||||||
load_paths = $-I.map {|p| "-I\"#{File.expand_path(p)}\"" }.join(" ")
|
load_paths = $-I.map {|p| "-I\"#{File.expand_path(p)}\"" }.join(" ")
|
||||||
`#{Gem.ruby} #{load_paths} #{$0} #{ORIG_ARGV.join(" ")}`
|
orig_args = ORIG_ARGV.join(" ")
|
||||||
|
test_opts = "-n#{self.class.name}##{self.name}"
|
||||||
|
command = "#{Gem.ruby} #{load_paths} #{$0} #{orig_args} #{test_opts}"
|
||||||
|
|
||||||
ENV.delete("ISOLATION_TEST")
|
# IO.popen lets us pass env in a cross-platform way
|
||||||
ENV.delete("ISOLATION_OUTPUT")
|
child = IO.popen([env, command])
|
||||||
|
|
||||||
|
begin
|
||||||
|
Process.wait(child.pid)
|
||||||
|
rescue Errno::ECHILD # The child process may exit before we wait
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
return tmpfile.read.unpack("m")[0]
|
return tmpfile.read.unpack("m")[0]
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue