Clean up Mongo databases created by the test suite.
This commit is contained in:
@@ -80,11 +80,15 @@ namespace :test do
|
||||
end
|
||||
|
||||
desc "Run acceptance tests for the #{system} without collectstatic or db migrations"
|
||||
task "#{system}:fast", [:harvest_args] => [
|
||||
:clean_reports_dir, ACCEPTANCE_REPORT_DIR,
|
||||
] do |t, args|
|
||||
task "#{system}:fast", [:harvest_args] => [:clean_reports_dir, ACCEPTANCE_REPORT_DIR] do |t, args|
|
||||
args.with_defaults(:harvest_args => '')
|
||||
run_acceptance_tests(system, args.harvest_args)
|
||||
|
||||
begin
|
||||
run_acceptance_tests(system, args.harvest_args)
|
||||
ensure
|
||||
Rake::Task[:'test:clean_mongo'].reenable
|
||||
Rake::Task[:'test:clean_mongo'].invoke
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -79,7 +79,15 @@ TEST_TASK_DIRS = []
|
||||
# messing with static files.
|
||||
task "fasttest_#{system}", [:test_id] => [test_id_dir, report_dir, :clean_reports_dir] do |t, args|
|
||||
args.with_defaults(:test_id => nil)
|
||||
run_tests(system, report_dir, args.test_id)
|
||||
|
||||
|
||||
|
||||
begin
|
||||
run_tests(system, report_dir, args.test_id)
|
||||
ensure
|
||||
Rake::Task[:'test:clean_mongo'].reenable
|
||||
Rake::Task[:'test:clean_mongo'].invoke
|
||||
end
|
||||
end
|
||||
|
||||
task :fasttest => "fasttest_#{system}"
|
||||
@@ -97,13 +105,18 @@ Dir["common/lib/*"].select{|lib| File.directory?(lib)}.each do |lib|
|
||||
|
||||
desc "Run tests for common lib #{lib}"
|
||||
task "test_#{lib}", [:test_id] => [
|
||||
test_id_dir, report_dir, :clean_test_files,
|
||||
:clean_reports_dir, :install_prereqs
|
||||
test_id_dir, report_dir, :clean_test_files, :clean_reports_dir, :install_prereqs
|
||||
] do |t, args|
|
||||
|
||||
args.with_defaults(:test_id => lib)
|
||||
ENV['NOSE_XUNIT_FILE'] = File.join(report_dir, "nosetests.xml")
|
||||
cmd = "nosetests --id-file=#{test_ids} #{args.test_id}"
|
||||
test_sh(lib, run_under_coverage(cmd, lib))
|
||||
begin
|
||||
test_sh(lib, run_under_coverage(cmd, lib))
|
||||
ensure
|
||||
Rake::Task[:'test:clean_mongo'].reenable
|
||||
Rake::Task[:'test:clean_mongo'].invoke
|
||||
end
|
||||
end
|
||||
TEST_TASK_DIRS << lib
|
||||
|
||||
@@ -128,6 +141,11 @@ end
|
||||
namespace :test do
|
||||
desc "Run all python tests"
|
||||
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
|
||||
|
||||
desc "Build the html, xml, and diff coverage reports"
|
||||
|
||||
24
scripts/delete-mongo-test-dbs.js
Normal file
24
scripts/delete-mongo-test-dbs.js
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user