Tag Archive for 'unittests'

How to use a RAM / memory disk for MySQL in Rails

I wanted to use a RAM disk for my MySQL data files when running my tests for a Rails project. I succeeded, but it only cut 2 seconds off of my ~30 second test suite for my functional tests, and didn't cut any time off of my unit tests. But nevertheless, here is how I achieved this, in case it is useful to others. All of this is on OS X, using MySQL 5 from Macports.

What we are doing is creating a RAM disk, and then creating a seperate MySQL instance that stores its data on that RAM disk.

BASH:
  1. # Create the RAM disk
  2. hdid -nomount ram://52428800
  3. newfs_hfs /dev/disk1
  4. mkdir /tmp/ramdisk1
  5. mount -t hfs /dev/disk1 /tmp/ramdisk1
  6.  
  7. # Initialize the MySQL environment
  8. mysql_install_db5 --datadir=/tmp/ramdisk1
  9.  
  10. # Start the MySQL server
  11. /opt/local/libexec/mysqld --basedir=/opt/local --datadir=/tmp/ramdisk1  --pid-file=/tmp/mysql_memory_localhost.pid --port=10000 --socket=/tmp/mysql_memory.sock
  12.  
  13. # Create your test database
  14. mysqladmin5 --socket=/tmp/mysql_memory.sock -uroot create projectname_test

Now in your database.yml file, add socket: /tmp/mysql_memory.sock to the test database configuration.

(thanks to this tutorial for how-to create a RAM disk in OS X)

Is rcov failing with a bus error? Here is the solution.

Is rcov failing with a bus error?

..../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:322: [BUG] Bus Error
ruby 1.8.4 (2005-12-24) [powerpc-darwin8.8.0]

rake aborted!
Command failed with status (): [/usr/local/bin/ruby -Ilib:test -S rcov --t...]

This has been happening to me inconsistently for months and driving me crazy. The solution is to use the --no-rcovrt flag, which will not use the c binding and will make rcov run, according to the help page, "30 to 300 times slower". A small price to pay for consistent test coverage reporting.

(I discovered the solution on this thread)




Close
Powered by ShareThis