Commit 8ee601a5 by Will Daly

Clean up Mongo databases created by the test suite.

parent 54f508a0
...@@ -80,11 +80,15 @@ namespace :test do ...@@ -80,11 +80,15 @@ namespace :test do
end end
desc "Run acceptance tests for the #{system} without collectstatic or db migrations" desc "Run acceptance tests for the #{system} without collectstatic or db migrations"
task "#{system}:fast", [:harvest_args] => [ task "#{system}:fast", [:harvest_args] => [:clean_reports_dir, ACCEPTANCE_REPORT_DIR] do |t, args|
:clean_reports_dir, ACCEPTANCE_REPORT_DIR,
] do |t, args|
args.with_defaults(:harvest_args => '') args.with_defaults(:harvest_args => '')
begin
run_acceptance_tests(system, args.harvest_args) run_acceptance_tests(system, args.harvest_args)
ensure
Rake::Task[:'test:clean_mongo'].reenable
Rake::Task[:'test:clean_mongo'].invoke
end
end end
end end
end end
......
...@@ -79,7 +79,15 @@ TEST_TASK_DIRS = [] ...@@ -79,7 +79,15 @@ TEST_TASK_DIRS = []
# messing with static files. # messing with static files.
task "fasttest_#{system}", [:test_id] => [test_id_dir, report_dir, :clean_reports_dir] do |t, args| task "fasttest_#{system}", [:test_id] => [test_id_dir, report_dir, :clean_reports_dir] do |t, args|
args.with_defaults(:test_id => nil) args.with_defaults(:test_id => nil)
begin
run_tests(system, report_dir, args.test_id) run_tests(system, report_dir, args.test_id)
ensure
Rake::Task[:'test:clean_mongo'].reenable
Rake::Task[:'test:clean_mongo'].invoke
end
end end
task :fasttest => "fasttest_#{system}" task :fasttest => "fasttest_#{system}"
...@@ -97,13 +105,18 @@ Dir["common/lib/*"].select{|lib| File.directory?(lib)}.each do |lib| ...@@ -97,13 +105,18 @@ Dir["common/lib/*"].select{|lib| File.directory?(lib)}.each do |lib|
desc "Run tests for common lib #{lib}" desc "Run tests for common lib #{lib}"
task "test_#{lib}", [:test_id] => [ task "test_#{lib}", [:test_id] => [
test_id_dir, report_dir, :clean_test_files, test_id_dir, report_dir, :clean_test_files, :clean_reports_dir, :install_prereqs
:clean_reports_dir, :install_prereqs
] do |t, args| ] do |t, args|
args.with_defaults(:test_id => lib) args.with_defaults(:test_id => lib)
ENV['NOSE_XUNIT_FILE'] = File.join(report_dir, "nosetests.xml") ENV['NOSE_XUNIT_FILE'] = File.join(report_dir, "nosetests.xml")
cmd = "nosetests --id-file=#{test_ids} #{args.test_id}" cmd = "nosetests --id-file=#{test_ids} #{args.test_id}"
begin
test_sh(lib, run_under_coverage(cmd, lib)) test_sh(lib, run_under_coverage(cmd, lib))
ensure
Rake::Task[:'test:clean_mongo'].reenable
Rake::Task[:'test:clean_mongo'].invoke
end
end end
TEST_TASK_DIRS << lib TEST_TASK_DIRS << lib
...@@ -128,6 +141,11 @@ end ...@@ -128,6 +141,11 @@ end
namespace :test do namespace :test do
desc "Run all python tests" desc "Run all python tests"
task :python, [:test_id] task :python, [:test_id]
desc "Drop Mongo databases created by the test suite"
task :clean_mongo do
sh("mongo #{REPO_ROOT}/scripts/delete-mongo-test-dbs.js")
end
end end
desc "Build the html, xml, and diff coverage reports" desc "Build the html, xml, and diff coverage reports"
......
/*
Drop all Mongo test databases.
Usage example:
mongo delete-mongo-test-dbs.js
will drop every database that starts with "test_" or "acceptance_",
but ignore other databases.
*/
String.prototype.startsWith = function(substring) {
return (this.indexOf(substring) == 0);
}
var dbNameList = db.getMongo().getDBNames();
for (var i in dbNameList) {
if (dbNameList[i].startsWith('test_') || dbNameList[i].startsWith('acceptance_')) {
dbToDrop = db.getMongo().getDB(dbNameList[i]);
print("Dropping test db " + dbNameList[i]);
dbToDrop.dropDatabase();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment