Skip to content

Commit 68b56cf

Browse files
authored
Always execute a Rake subtask using the same Rake executable (#865)
Rather than trying to find a suitable Rake executable, assume the currently running Rake is the user's preferred executable. It will allow for the most correctness in the subprocess environment. For documentation on $0, see: https://ruby-doc.org/core-3.1.2/doc/globals_rdoc.html > Contains the name of the script being executed.
1 parent fe56bf8 commit 68b56cf

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
### Added
88

9+
- Changed Rake subtasks to always use the same Rake executable as the parent
10+
process.
11+
912
### Fixed
1013

1114
## 3.9.1 - 2022-05-23

lib/parallel_tests/tasks.rb

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ def rails_env
99
'test'
1010
end
1111

12-
def rake_bin
13-
# Prevent 'Exec format error' Errno::ENOEXEC on Windows
14-
return "rake" if RUBY_PLATFORM =~ /mswin|mingw|cygwin/
15-
binstub_path = File.join('bin', 'rake')
16-
return binstub_path if File.exist?(binstub_path)
17-
"rake"
18-
end
19-
2012
def load_lib
2113
$LOAD_PATH << File.expand_path('..', __dir__)
2214
require "parallel_tests"
@@ -126,14 +118,14 @@ def rails_61_or_greater?
126118
namespace :parallel do
127119
desc "Setup test databases via db:setup --> parallel:setup[num_cpus]"
128120
task :setup, :count do |_, args|
129-
command = [ParallelTests::Tasks.rake_bin, "db:setup", "RAILS_ENV=#{ParallelTests::Tasks.rails_env}"]
121+
command = [$0, "db:setup", "RAILS_ENV=#{ParallelTests::Tasks.rails_env}"]
130122
ParallelTests::Tasks.run_in_parallel(ParallelTests::Tasks.suppress_schema_load_output(command), args)
131123
end
132124

133125
desc "Create test databases via db:create --> parallel:create[num_cpus]"
134126
task :create, :count do |_, args|
135127
ParallelTests::Tasks.run_in_parallel(
136-
[ParallelTests::Tasks.rake_bin, "db:create", "RAILS_ENV=#{ParallelTests::Tasks.rails_env}"],
128+
[$0, "db:create", "RAILS_ENV=#{ParallelTests::Tasks.rails_env}"],
137129
args
138130
)
139131
end
@@ -142,7 +134,7 @@ def rails_61_or_greater?
142134
task :drop, :count do |_, args|
143135
ParallelTests::Tasks.run_in_parallel(
144136
[
145-
ParallelTests::Tasks.rake_bin,
137+
$0,
146138
"db:drop",
147139
"RAILS_ENV=#{ParallelTests::Tasks.rails_env}",
148140
"DISABLE_DATABASE_ENVIRONMENT_CHECK=1"
@@ -169,7 +161,7 @@ def rails_61_or_greater?
169161
# slow: dump and load in in serial
170162
args = args.to_hash.merge(non_parallel: true) # normal merge returns nil
171163
task_name = Rake::Task.task_defined?('db:test:prepare') ? 'db:test:prepare' : 'app:db:test:prepare'
172-
ParallelTests::Tasks.run_in_parallel([ParallelTests::Tasks.rake_bin, task_name], args)
164+
ParallelTests::Tasks.run_in_parallel([$0, task_name], args)
173165
next
174166
end
175167
end
@@ -178,15 +170,15 @@ def rails_61_or_greater?
178170
desc "Update test databases via db:migrate --> parallel:migrate[num_cpus]"
179171
task :migrate, :count do |_, args|
180172
ParallelTests::Tasks.run_in_parallel(
181-
[ParallelTests::Tasks.rake_bin, "db:migrate", "RAILS_ENV=#{ParallelTests::Tasks.rails_env}"],
173+
[$0, "db:migrate", "RAILS_ENV=#{ParallelTests::Tasks.rails_env}"],
182174
args
183175
)
184176
end
185177

186178
desc "Rollback test databases via db:rollback --> parallel:rollback[num_cpus]"
187179
task :rollback, :count do |_, args|
188180
ParallelTests::Tasks.run_in_parallel(
189-
[ParallelTests::Tasks.rake_bin, "db:rollback", "RAILS_ENV=#{ParallelTests::Tasks.rails_env}"],
181+
[$0, "db:rollback", "RAILS_ENV=#{ParallelTests::Tasks.rails_env}"],
190182
args
191183
)
192184
end
@@ -195,7 +187,7 @@ def rails_61_or_greater?
195187
desc "Load dumped schema for test databases via db:schema:load --> parallel:load_schema[num_cpus]"
196188
task :load_schema, :count do |_, args|
197189
command = [
198-
ParallelTests::Tasks.rake_bin,
190+
$0,
199191
ParallelTests::Tasks.purge_before_load,
200192
"db:schema:load",
201193
"RAILS_ENV=#{ParallelTests::Tasks.rails_env}",
@@ -210,7 +202,7 @@ def rails_61_or_greater?
210202
task :load_structure, :count do |_, args|
211203
ParallelTests::Tasks.run_in_parallel(
212204
[
213-
ParallelTests::Tasks.rake_bin,
205+
$0,
214206
ParallelTests::Tasks.purge_before_load,
215207
"db:structure:load",
216208
"RAILS_ENV=#{ParallelTests::Tasks.rails_env}",
@@ -224,7 +216,7 @@ def rails_61_or_greater?
224216
task :seed, :count do |_, args|
225217
ParallelTests::Tasks.run_in_parallel(
226218
[
227-
ParallelTests::Tasks.rake_bin,
219+
$0,
228220
"db:seed",
229221
"RAILS_ENV=#{ParallelTests::Tasks.rails_env}"
230222
],
@@ -235,7 +227,7 @@ def rails_61_or_greater?
235227
desc "Launch given rake command in parallel"
236228
task :rake, :command, :count do |_, args|
237229
ParallelTests::Tasks.run_in_parallel(
238-
[ParallelTests::Tasks.rake_bin, args.command, "RAILS_ENV=#{ParallelTests::Tasks.rails_env}"],
230+
[$0, args.command, "RAILS_ENV=#{ParallelTests::Tasks.rails_env}"],
239231
args
240232
)
241233
end

0 commit comments

Comments
 (0)