Skip to content

Commit fc66b52

Browse files
committed
Use Bundler.with_clear_env instead
1 parent 325af28 commit fc66b52

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

lib/benchmark_suite.rb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,17 @@ def run(ruby:, ruby_description:)
4848

4949
result_json_path = caller_json_path || File.join(out_path, "temp#{Process.pid}.json")
5050
cmd_prefix = base_cmd(ruby_description, entry.name)
51-
result = run_single_benchmark(entry.script_path, result_json_path, ruby, cmd_prefix, env, entry.name)
51+
52+
# Clear project-level Bundler environment so benchmarks run in a clean context.
53+
# Benchmarks that need Bundler (e.g., railsbench) set up their own via use_gemfile.
54+
# This is important when running tests under `bundle exec rake test`.
55+
result = if defined?(Bundler)
56+
Bundler.with_unbundled_env do
57+
run_single_benchmark(entry.script_path, result_json_path, ruby, cmd_prefix, env, entry.name)
58+
end
59+
else
60+
run_single_benchmark(entry.script_path, result_json_path, ruby, cmd_prefix, env, entry.name)
61+
end
5262

5363
if result[:success]
5464
bench_data[entry.name] = process_benchmark_result(result_json_path, result[:command], delete_file: !caller_json_path)
@@ -177,15 +187,6 @@ def benchmark_env(ruby)
177187
end
178188
end
179189

180-
# Clear Bundler environment variables to prevent the parent's bundle context
181-
# from leaking into benchmark subprocesses. Benchmarks that need Bundler will
182-
# set up their own context via use_gemfile in the harness.
183-
# This is especially important when running tests under `bundle exec rake test`.
184-
["BUNDLE_GEMFILE", "BUNDLE_BIN_PATH", "BUNDLE_PATH", "BUNDLER_VERSION",
185-
"BUNDLER_SETUP", "RUBYOPT", "RUBYLIB"].each do |var|
186-
env[var] = nil if ENV.key?(var)
187-
end
188-
189190
env
190191
end
191192

0 commit comments

Comments
 (0)