Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All memory consumed when running tests #614

Closed
seanlinsley opened this issue Jul 29, 2014 · 2 comments
Closed

All memory consumed when running tests #614

seanlinsley opened this issue Jul 29, 2014 · 2 comments

Comments

@seanlinsley
Copy link

I'm currently working on activeadmin/activeadmin#3298 to get Active Admin's test suite passing again using the latest version of RSpec. As noted on that ticket, I can't locally reproduce the error that Travis is failing on; instead I discovered that a823c9f in particular causes all available memory to be consumed.

This issue seems to only occur for a single test, which happens to use include.

rspec spec/unit/views/components/paginated_collection_spec.rb:47

I can reproduce this on both Ruby 2.1.1 and 2.1.2. I made sure to bundle update during all this, but let me know if you'd still like a Gemfile.lock

@myronmarston
Copy link
Member

Thanks for providing clear repro instructions!

The memory consumption happens because in that spec, pagination is defined in such a way that [pagination].flatten will recurse infinitely (but will do so in a way that doesn't exhaust the stack!), causing the memory consumption spike. You can see this happen if you remove the expect lines and put [pagination].flatten instead -- you'll get the same thing. There's a spot internally in RSpec where it flattens an array that happens to have your object in it, and it hits this.

I believe the source of the problem is the fact that Arbre::Element#to_ary is defined in such a way that it includes self in the returned collection:

https://github.com/gregbell/arbre/blob/fe4738844d7d4b9db0b1b46af889310854cd316e/lib/arbre/element.rb#L149-L151

flatten recursively calls to_ary on the receiver, then on the individual elements returned by that, then on the individual elements returned by that, etc, so as long as you are including self in the return value of to_ary, it will recurse forever.

As it turns out, rack and rails have both had this bug in the past:

...so you may be able to use a similar solution to how they solved it.

@seanlinsley
Copy link
Author

I can reproduce as well with Arbre::Element.new.to_a.flatten. Thanks for looking into this 🐱

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants