Created
June 9, 2010 20:48
-
-
Save lukemelia/432144 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How we're using Hydra's listener and messaging architecture to have each runner spin up a database after it boots. See also: http://github.com/ngauthier/hydra/wikis/multiple-test-databases |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'hydra' | |
require 'hydra/tasks' | |
Hydra::TestTask.new('hydra:specs') do |t| | |
require 'hydra_extensions' | |
t.verbose = !!ENV['VERBOSE'] | |
t.listeners << HydraExtensions::Listener::MultipleDatabases.new | |
t.add_files 'spec/**/*_spec.rb' | |
end | |
Hydra::TestTask.new('hydra:features') do |t| | |
require 'hydra_extensions' | |
t.verbose = !!ENV['VERBOSE'] | |
t.listeners << HydraExtensions::Listener::MultipleDatabases.new | |
t.autosort = false | |
t.add_files 'features/activity_feeds/*.feature' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'hydra_extensions/listener/multiple_databases' | |
require 'hydra_extensions/messages/master_messages' | |
require 'hydra_extensions/messages/worker_messages' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module HydraExtensions | |
module Messages | |
module Master | |
class CreateDatabases < Hydra::Message | |
def handle(worker) | |
worker.runners.each do |runner| | |
runner[:io].write(HydraExtensions::Messages::Worker::CreateDatabase.new) | |
end | |
end | |
end | |
class DropDatabases < Hydra::Message | |
def handle(worker) | |
worker.runners.each do |runner| | |
runner[:io].write(HydraExtensions::Messages::Worker::DropDatabase.new) | |
end | |
end | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module HydraExtensions | |
module Listener | |
class MultipleDatabases < Hydra::Listener::Abstract | |
def worker_begin(worker) | |
worker[:io].write(HydraExtensions::Messages::Master::CreateDatabases.new) | |
end | |
# Fired before shutting down the worker | |
def worker_end(worker) | |
worker[:io].write(HydraExtensions::Messages::Master::DropDatabases.new) if worker[:io] | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module HydraExtensions | |
module Messages | |
module Worker | |
# Message telling the runner to create database. | |
class CreateDatabase < Hydra::Message | |
def handle(runner) | |
ENV['TEST_ENV_NUMBER'] = "hydra_#{Process.pid}" | |
schema_file = Rails.root.join('db','development_structure.sql') | |
`/usr/local/mysql/bin/mysql -u root -f -e 'drop database if exists #{ENV['TEST_ENV_NUMBER']}'` | |
`/usr/local/mysql/bin/mysqladmin -u root create #{ENV['TEST_ENV_NUMBER']}` | |
`/usr/local/mysql/bin/mysql -u root #{ENV['TEST_ENV_NUMBER']} < #{schema_file}` | |
end | |
end | |
class DropDatabase < Hydra::Message | |
def handle(runner) | |
`/usr/local/mysql/bin/mysqladmin -u root -f drop #{ENV['TEST_ENV_NUMBER']}` | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment