Just a Typical Rails Testing Session
Goal: Find out how fast this code runs.
Solution: Write a performance test using Rails’ built-in script/generate performance_test
Steps:
- script/generate performance_test homepage
- edit test/performance/homepage_test.rb
- Oh wait, I don’t have a test database set up
- ssh dev
- pg_dump -Fc devdb > db.dump
- exit
- scp dev:~/db.dump .
- Wait for 700Mb compressed dump file to download over wi-fi connection
- pg_restore -d testdb db.dump
- errors: could not access $libdir/pg_trgm, $libdir/uuid-ossp, $libdir/fuzzystrmatch, tons of no relation errors
- Search Google: what is all this stuff?
- uuid-ossp depends on http://www.ossp.org/pkg/lib/uuid/
- Download, untar, configure, make, make install
- Oops, forgot to build with postgres support
- GOTO 13 and return
- That didn’t work; GOTO 11 and return
- Oh, compiling uuid-ossp on Mac has problems: http://cvs.ossp.org/tktview?tn=81
- Try running one user’s suggestion of renaming uuid_t
rgrep -l uuid_t | grep -v ChangeLog | xargs perl -i -pe 's/uuid_t/ossp_uuid_t/g'- rgrep: command not found
- GOTO 11 and return
- sudo port install rgrep (nope)
- Is rgrep source available? (nope)
- Ah, rgrep is part of the jed text editor
- sudo port install jed (installs slang and jed)
- GOTO 19, 20, (swear once), 21
- What was my goal again?
- locate rgrep (nope)
- locate jed (nope)
- How do you update the locate db again? GOTO 11 and return
- sudo /usr/libexec/locate.updatedb (receive warning, “the Lord will kill you for running as root”)
- Why am I doing this?
- I know, I’ll write a funny post on how great it is to be a programmer and how 90% of your time is debugging your system or your code (because no one’s ever written about that before)
- Let’s go over the steps again, start from the beginning
- rake test:benchmark (database structure loads with errors, but the test runs; what?!)
- “rake aborted: undefined method
`use_transactional_fixtures=' for Test::Unit::TestCase:Class" - edit test_helper.rb: replace
Test::Unit::TestCasewithActiveSupport::TestCase - rake test:benchmark (it works: “wall_time: 5 ms”)
- GOTO 32 and return
- Why are memory, objects, gc_runs, and gc_time all zero?
- GOTO 11 and return
- Oh, I need to patch Ruby with a GC patch
- cd /usr/local/src/ruby-1.8.6-p369
- curl http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch | patch -p0
- “8 out of 28 hunks FAILED”
- Does it compile? ./configure; make (error)
- Oh well
- GOTO 27 and return