Skeleton Listener to help with setting up a separate database for each worker. Calls dump_schema, load_schema, create_database, and drop_database hooks provided by subclasses that implement database setup strategies for particular database flavors.
Called on each worker after creating database and before loading schema to initialize connections
# File lib/deep_test/database/setup_listener.rb, line 44 def connect_to_database ActiveRecord::Base.establish_connection(worker_database_config) end
Called in each worker to create the database named by worker_database.
# File lib/deep_test/database/setup_listener.rb, line 52 def create_database raise "Subclass must implement" end
Called in each worker to drop the database created by create_database. This method is called twice, once before create_database to ensure that no database exists and once at exit to clean as the worker process exits. This method must not fail if the database does not exist when it is called.
# File lib/deep_test/database/setup_listener.rb, line 63 def drop_database raise "Subclass must implement" end
Called before any workers are spawned to dump the schema that will be used for testing. When running distributed, this method is called on the local machine providing the tests to run.
For distributed testing to work, the schema must be dumped in location accessible by all worker machines. The easiest way to accomplish this is to dump it to a location within the working copy.
# File lib/deep_test/database/setup_listener.rb, line 76 def dump_schema raise "Subclass must implement" end
Called once in each worker as it is starting to load the schema dumped from dump_schema. Subclasses should load the schema definition into the worker_database
# File lib/deep_test/database/setup_listener.rb, line 86 def load_schema raise "Subclass must implement" end
ActiveRecord configuration for the master database, based on RAILS_ENV. If not running Rails, you'll need to override this to provide the correct configuration.
# File lib/deep_test/database/setup_listener.rb, line 104 def master_database_config ActiveRecord::Base.configurations[RAILS_ENV].with_indifferent_access end
Unique name for database on machine that worker is running on.
# File lib/deep_test/database/setup_listener.rb, line 111 def worker_database "deep_test_worker_#{@worker.number}_pid_#{Process.pid}" end
ActiveRecord configuration for the worker database. By default, the same as master_database_config, except that points to worker_database instead of the database named in the master config.
# File lib/deep_test/database/setup_listener.rb, line 95 def worker_database_config master_database_config.merge(:database => worker_database) end
Generated with the Darkfish Rdoc Generator 2.