Skip to content

Commit

Permalink
[rubygems/rubygems] Make slow perf specs more stable
Browse files Browse the repository at this point in the history
This seems worse to detect performance regressions, but at least should
not have many false positives.

rubygems/rubygems@0b28e55415
  • Loading branch information
deivid-rodriguez authored and matzbot committed Jan 31, 2024
1 parent c70052e commit a322b2f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 31 deletions.
18 changes: 13 additions & 5 deletions spec/bundler/realworld/slow_perf_spec.rb
Expand Up @@ -11,7 +11,8 @@
gem "mongoid", ">= 0.10.2"
G

expect { bundle "lock" }.to take_less_than(18) # seconds
bundle "lock", env: { "DEBUG_RESOLVER" => "1" }
expect(out).to include("Solution found after 1 attempts")
end

it "resolves quickly (case 2)" do
Expand All @@ -28,7 +29,8 @@
gem 'rspec-rails'
G

expect { bundle "lock" }.to take_less_than(30) # seconds
bundle "lock", env: { "DEBUG_RESOLVER" => "1" }
expect(out).to include("Solution found after 1 attempts")
end

it "resolves big gemfile quickly" do
Expand Down Expand Up @@ -129,8 +131,14 @@
end
G

expect do
bundle "lock", env: { "DEBUG_RESOLVER" => "1" }, raise_on_error: !Bundler.feature_flag.bundler_3_mode?
end.to take_less_than(30) # seconds
if Bundler.feature_flag.bundler_3_mode?
bundle "lock", env: { "DEBUG_RESOLVER" => "1" }, raise_on_error: false

expect(out).to include("backtracking").exactly(26).times
else
bundle "lock", env: { "DEBUG_RESOLVER" => "1" }

expect(out).to include("Solution found after 10 attempts")
end
end
end
26 changes: 0 additions & 26 deletions spec/bundler/support/matchers.rb
Expand Up @@ -97,32 +97,6 @@ def self.define_compound_matcher(matcher, preconditions, &declarations)
end
end

RSpec::Matchers.define :take_less_than do |seconds|
match do |actual|
start_time = Time.now

actual.call

actual_time = (Time.now - start_time).to_f

acceptable = actual_time < seconds

@errors = ["took #{actual_time} seconds"] unless acceptable

acceptable
end

failure_message do
super() + " but:\n" + @errors.map {|e| indent(e) }.join("\n")
end

failure_message_when_negated do
super() + " but:\n" + @errors.map {|e| indent(e) }.join("\n")
end

supports_block_expectations
end

define_compound_matcher :read_as, [exist] do |file_contents|
diffable

Expand Down

0 comments on commit a322b2f

Please sign in to comment.