Skip to content

100% CPU when comparing ActiveController::TestResponse with a primitive #601

@timothyandrew

Description

@timothyandrew

We ran into a bug today which pushed our CPU up to 100% and forced us to restart our Mac.

Our test case was something like:

it "returns all the info for a User in JSON excluding password" do
  user = FactoryGirl.create(:user)
  get :show, :id => user.id
  response.should == user.as_json(except: :password_digest)
end

This is a mistake…we intended to test response.body, not response. However running this code made the machine completely unresponsive, with the CPU up at 100%.

When we investigated this further (on multiple macs), it seems like comparing a response with any Ruby primitive seems to freeze the test and push the CPU up to 100%.

response.should == {} # 100% CPU
response.should == []  # 100% CPU
ActiveController::TestResponse.new.should == {}  # 100% CPU
ActiveController::TestResponse.new.should == ".."  # 100% CPU
ActionDispatch::TestResponse.new.should == {}  # 100% CPU
request.should == {} # Test runs fine
response.body.should == {} # Test runs fine

Is this an RSpec bug?

Best,
@timothyandrew & @Who828

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions