testdouble / jasmine-rails

A Jasmine runner for rails projects that's got you covered in both the terminal and the browser
http://rubygems.org/gems/jasmine-rails
MIT License
378 stars 154 forks source link

Work around PhantomJS 2 memory consumption issue #194

Closed seanlinsley closed 8 years ago

seanlinsley commented 8 years ago

http://stackoverflow.com/questions/24436460 https://github.com/ariya/phantomjs/issues/10357 https://github.com/ariya/phantomjs/commit/5768b705a0

Without this change, PhantomJS 2 consumes all available memory (at least 8 GB) with our test suite.

searls commented 8 years ago

Welp this is terrible. I'll take your word for it.

searls commented 8 years ago

Landed in 0.12.5

seanlinsley commented 8 years ago

Yeah it's pretty terrible, and took a long time to isolate. Even better, Circle CI has some weird configuration where this change doesn't help. Or perhaps it's a problem unique to Ubuntu: #13805.

seanlinsley commented 8 years ago

Thanks for merging this! It at least makes it possible for us to run our tests locally 😅

eromoe commented 7 years ago

I am using phantomjs as a crawler middleware, I want to clear cache after every page.open complete, and google lead me to here.

I wonder why here set setInterval(page.clearMemoryCache, 500) on every page.open.

  1. Isn't 500 too short if that url has many large js need run?
  2. setInterval would run forever, why not use onetime setTimeout ?
dealingwith commented 7 years ago

Upon further investigation is it actually the assignment of phantom.onError that causes the memory leak. Simply removing that line, the tests run as expected. (Alternatively, having javascript that never throws errors also works.)

To try to help fix the bug, I need to know more about why that line is there in the first place.

searls commented 7 years ago

Heh, I was going to ask you why that line was there.

I have no recollection at all off-hand, and a few minutes of blaming led me to this commit by @wireframe https://github.com/searls/jasmine-rails/commit/39459c0a3a2946ae6ad8c74af7ad4984695526b3

dealingwith commented 7 years ago

Well, I don't know much yet, but the implementation here is almost verbatim from the example on phantomjs.org

searls commented 7 years ago

Ugh. I'm not very close to this. Does anyone want to chime in on what they think we should do?