Skip to content

Commit

Permalink
Adjust specs for cleaner testing on Travis.
Browse files Browse the repository at this point in the history
Also, provide default rake tasks for lib and vmdb directory for testing.
  • Loading branch information
Fryguy committed Sep 24, 2014
1 parent c9b2cec commit 2679b31
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 45 deletions.
14 changes: 8 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ env:
- BUNDLE_WITHOUT=development:metric_fu:qpid
- RUBY_GC_MALLOC_LIMIT=90000000
matrix:
- TEST_SUITE=lib
- TEST_SUITE=vmdb
- TEST_SUITE=migrations
- TEST_SUITE=replication
- TEST_SUITE=automation
- TEST_SUITE=lib TEST_ROOT=lib
- TEST_SUITE=vmdb TEST_ROOT=vmdb
- TEST_SUITE=migrations TEST_ROOT=vmdb
- TEST_SUITE=replication TEST_ROOT=vmdb
- TEST_SUITE=automation TEST_ROOT=vmdb
addons:
postgresql: '9.3'
before_install:
Expand All @@ -21,4 +21,6 @@ before_install:
- travis_retry gem install rake -v10.1.1
- psql -c "CREATE USER root SUPERUSER PASSWORD 'smartvm';" -U postgres
- rake build:shared_objects:clean build:shared_objects
script: rake test:$TEST_SUITE
- cd $TEST_ROOT
before_script: bundle exec rake test:setup_$TEST_SUITE
script: bundle exec rake test:$TEST_SUITE
12 changes: 6 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ namespace :test do
desc "Runs EVM vmdb specs"
task :vmdb do
ENV['RAILS_ENV'] = 'test'
['test:load_vmdb_tasks', 'evm:test:setup', 'spec:evm:backend'].each { |t| Rake::Task[t].invoke }
['test:load_vmdb_tasks', 'evm:test:setup', 'test:vmdb'].each { |t| Rake::Task[t].invoke }
end

desc "Run EVM migration specs"
task :migrations do
ENV['RAILS_ENV'] = 'test'
['test:load_vmdb_tasks', 'evm:test:setup_migrations', 'spec:evm:migrations:up', 'evm:test:complete_migrations:up', 'spec:evm:migrations:down', 'evm:test:complete_migrations:down'].each { |t| Rake::Task[t].invoke }
['test:load_vmdb_tasks', 'evm:test:setup', 'test:migrations'].each { |t| Rake::Task[t].invoke }
end

desc "Run EVM replication specs"
task :replication do
ENV['RAILS_ENV'] = 'test'
['test:load_vmdb_tasks', 'evm:test:setup_replication', 'spec:evm:replication'].each { |t| Rake::Task[t].invoke }
['test:load_vmdb_tasks', 'evm:test:initialize', 'evm:test:setup_replication', 'test:replication'].each { |t| Rake::Task[t].invoke }
end

desc "Run EVM automation specs"
task :automation do
ENV['RAILS_ENV'] = 'test'
['test:load_vmdb_tasks', 'evm:test:setup', 'spec:evm:automation'].each { |t| Rake::Task[t].invoke }
['test:load_vmdb_tasks', 'evm:test:setup', 'test:automation'].each { |t| Rake::Task[t].invoke }
end

desc "Run metric_fu metrics"
Expand All @@ -43,8 +43,8 @@ namespace :test do
end

desc "Runs EVM lib tests in a single block"
task :lib do
['test:load_lib_tasks', :spec, :test].each { |t| Rake::Task[t].invoke }
task :run_lib do
['test:load_lib_tasks', 'test:lib'].each { |t| Rake::Task[t].invoke }
end

task :load_vmdb_tasks do
Expand Down
2 changes: 0 additions & 2 deletions lib/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ require 'rdoc/task'

LIB_ROOT = File.expand_path(File.dirname(__FILE__))
Dir["#{LIB_ROOT}/lib/tasks/**/*.rake"].sort.each { |ext| load ext }

task :default => [:test]
11 changes: 2 additions & 9 deletions lib/lib/tasks/rspec.rake
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
require 'rspec/core'
require 'rspec/core/rake_task'
if default = Rake.application.instance_variable_get('@tasks')['default']
default.prerequisites.delete('test')
end

spec_prereq = :noop
task :noop do; end
task :default => :spec

desc "Run all specs in spec directory"
RSpec::Core::RakeTask.new(:spec => spec_prereq) do |t|
RSpec::Core::RakeTask.new(:spec) do |t|
rspec_opts_file = ".rspec#{"_ci" if ENV['CI']}"
t.rspec_opts = ['--options', "\"#{File.expand_path(File.join(File.dirname(__FILE__), rspec_opts_file))}\""]
t.verbose = false
end

namespace :spec do
desc "Run all specs with rcov"
RSpec::Core::RakeTask.new(:rcov => spec_prereq) do |t|
RSpec::Core::RakeTask.new(:rcov) do |t|
rspec_opts_file = ".rspec#{"_ci" if ENV['CI']}"
t.rspec_opts = ['--options', "\"#{File.expand_path(File.join(File.dirname(__FILE__), rspec_opts_file))}\""]
t.verbose = false
Expand Down
8 changes: 8 additions & 0 deletions lib/lib/tasks/test.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace :test do
task :setup_lib # NOOP - Stub for consistent CI testing

desc "Run all lib specs and tests except MiqDisk tests"
task :lib => [:spec, :test]
end

task :default => 'test:lib'
8 changes: 8 additions & 0 deletions vmdb/lib/tasks/evm_test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module EvmTestHelper
def self.run_rake_via_shell(rake_command, env = {})
cmd = "bundle exec rake #{rake_command}"
cmd << " --trace" if Rake.application.options.trace
_pid, status = Process.wait2(Kernel.spawn(env, cmd, :chdir => Rails.root))
exit(status.exitstatus) if status.exitstatus != 0
end
end
18 changes: 4 additions & 14 deletions vmdb/lib/tasks/evm_test_migrations.rake
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
require_relative "./evm_test_helper"

namespace :evm do
namespace :test do
task :setup_migrations => 'evm:test:initialize' do
puts "** Preparing migrations database"
run_rake_via_shell("evm:db:destroy")
end

namespace :complete_migrations do
task :up do
puts "** Migrating all the way up"
run_rake_via_shell("db:migrate")
EvmTestHelper.run_rake_via_shell("db:migrate", "VERBOSE" => ENV["VERBOSE"] || "false")
end

task :down do
puts "** Migrating all the way down"
run_rake_via_shell("db:migrate VERSION=0")
EvmTestHelper.run_rake_via_shell("db:migrate", "VERSION" => "0", "VERBOSE" => ENV["VERBOSE"] || "false")
end
end
end
end

def run_rake_via_shell(rake_command)
cmd = "rake #{rake_command}"
cmd << " --trace" if Rake.application.options.trace
pid, status = Process.wait2(Kernel.spawn(cmd, :chdir => Rails.root))
exit(status.exitstatus) if status.exitstatus != 0
end
21 changes: 13 additions & 8 deletions vmdb/lib/tasks/evm_test_replication.rake
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
namespace :evm do
namespace :test do
task :setup_replication => 'evm:test:initialize' do
task :setup_replication do
EvmTestSetupReplication.new.execute
end
end
end

require_relative "./evm_test_helper"

class EvmTestSetupReplication
def initialize
@db_yaml_file = Rails.root.join("config", "database.yml")
Expand All @@ -23,7 +25,7 @@ class EvmTestSetupReplication

def prepare_slave_database
puts "** Preparing slave database"
run_rake_via_shell("evm:db:reset")
db_reset
end

def prepare_master_database
Expand All @@ -36,12 +38,20 @@ class EvmTestSetupReplication
config["test"]["database"] += "_master"
File.open(@db_yaml_file, "w") { |f| f.puts(config.to_yaml) }

run_rake_via_shell("evm:db:reset")
db_reset
ensure
restore_system_files
end
end

def db_reset
env = {
"RAILS_ENV" => ENV["RAILS_ENV"] || "test",
"VERBOSE" => ENV["VERBOSE"] || "false",
}
EvmTestHelper.run_rake_via_shell("evm:db:reset", env)
end

def backup_system_files
FileUtils.cp(@db_yaml_file, @db_yaml_file_orig)
FileUtils.cp(@region_file, @region_file_orig) if File.exists?(@region_file)
Expand All @@ -55,9 +65,4 @@ class EvmTestSetupReplication
FileUtils.rm(@region_file)
end
end

def run_rake_via_shell(rake_command)
pid, status = Process.wait2(Kernel.spawn("rake #{rake_command}", :chdir => Rails.root))
exit(status.exitstatus) if status.exitstatus != 0
end
end
28 changes: 28 additions & 0 deletions vmdb/lib/tasks/test.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace :test do
task :setup_db do
ENV['RAILS_ENV'] ||= "test"
Rails.env = ENV['RAILS_ENV'] if defined?(Rails)

ENV['VERBOSE'] ||= "false"
Rake::Task['evm:db:reset'].invoke
end

task :setup_vmdb => :setup_db
task :setup_migrations => :setup_db
task :setup_replication => 'evm:test:setup_replication'
task :setup_automation => :setup_db

desc "Runs all specs except migrations, replication, automation, and requests"
task :vmdb => 'spec:evm:backend'

desc "Runs all migration specs"
task :migrations => ['spec:evm:migrations:down', 'evm:test:complete_migrations:down', 'spec:evm:migrations:up', 'evm:test:complete_migrations:up']

desc "Runs all replication specs"
task :replication => 'spec:evm:replication'

desc "Runs all automation specs"
task :automation => 'spec:evm:automation'
end

task :default => 'test:vmdb'

0 comments on commit 2679b31

Please sign in to comment.