OS X, PhantomJS and the Phantom Processes
23 Mar 2016 · 📖 in 1 minute Ghosts in the machine?I use PhantomJS to run headless Jasmine / QUnit tests.
This has worked flawlessly for the year or so I’ve been on this project and I have built quite a little automation empire... until recently.
I noticed that my machine was running loudly, which is strange for the MacBook Pro
as usually it breezes through build automation I put it through. Then I noticed
something weird. In the OS X Activity Monitor there was 10’s of phantomjs
processes active.
PhantomJS
The usual avenues yielded nothing, not google nor StackOverflow were able to shed any light on why I had so many of these processes running.
After putting up with it for nearly a week I decided I needed to get to the
bottom of it (my patch and fix solution of sudo killall phantomjs
was leaving
a bitter taste in my mouth, each execution feeling like another failure).
So, after some head-scratching I decided to run the tests in Safari, to see if there were any differences between it and PhantomJS. Almost immediately I saw the problem, after running my tests there was a timer that kept firing.
##### _How could I have missed that!?_
Looking back at my tests, I had added async testing of a reporter into my suite which was passing, but once the test finished I wasn’t clearing up and the timer would continue to event - keeping PhantomJS running. After I correctly cleared up the tests all was well with the world again.
Lesson Learnt?
Async testing isn’t difficult, the unit tests were easy to write and exercise the code completely. I was caught out by no cleaning up the tests afterwards, something I’ll certainly be careful of next time.
First appeared on Trusty Interior, last update 14 Nov 2023