Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use different db in travis parallel.

  • Loading branch information...
commit 40cc7b23fdb5e9c266f776c7e9d88e908ae55a6d 1 parent f5ee7a0
@saberma saberma authored
Showing with 42 additions and 30 deletions.
  1. +6 −1 .travis.yml
  2. +36 −19 Rakefile
  3. +0 −10 config/database.yml.example
View
7 .travis.yml
@@ -12,8 +12,9 @@ script:
- "cp config/database.yml.example config/database.yml 2>&1"
- "cp config/app_secret_config.yml.example config/app_secret_config.yml 2>&1"
- "cp config/initializers/secret_token.rb.example config/initializers/secret_token.rb 2>&1"
+ - "bundle exec rake travis:init_db"
- "bundle exec rake db:drop db:create db:schema:load --trace 2>&1"
- - "bundle exec rake travis"
+ - "bundle exec rake travis:parallel"
env:
- UNIT_TEST=1 # 单元测试1
@@ -21,11 +22,15 @@ env:
- UNIT_TEST=3 # 单元测试3
- UNIT_TEST=4 # 单元测试4
- UNIT_TEST=5 # 单元测试5
+ - UNIT_TEST=6 # 单元测试6
+ - UNIT_TEST=7 # 单元测试7
- INTEGRATE_TEST=1 # 集成测试1
- INTEGRATE_TEST=2 # 集成测试2
- INTEGRATE_TEST=3 # 集成测试3
- INTEGRATE_TEST=4 # 集成测试4
- INTEGRATE_TEST=5 # 集成测试5
+ - INTEGRATE_TEST=6 # 集成测试6
+ - INTEGRATE_TEST=7 # 集成测试7
#notifications:
# recipients:
View
55 Rakefile
@@ -10,26 +10,43 @@ task "resque:setup" => :environment do
Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection } # 第二次执行resque任务时失败 PGError: ERROR: prepared statement "a3" already exists 参考 http://j.mp/rpVqhc http://j.mp/rqj9CQ ;Rails已经打了补丁,未发布版本 http://j.mp/ntPQMr
end
-task :travis do
- parallel_size = 5
- unit_test = ENV['UNIT_TEST']
- integrate_test = ENV['INTEGRATE_TEST']
- all_files = Dir.chdir(Rails.root) { Dir["spec/**/*_spec.rb"]}.sort
- integrate_files = Dir.chdir(Rails.root) { Dir["spec/requests/**/*_spec.rb"]}.sort
- unit_files = all_files - integrate_files
- %w(shop/shops_searches_spec.rb lookup_spec.rb).each do |searchable_spec|
- integrate_files.delete "spec/requests/#{searchable_spec}" # 需要solr才能运行
+namespace :travis do
+
+ desc "Init database"
+ task :init_db do # 并发时使用不同的数据库,否则偶尔会死锁(deadlock detected)
+ unit_test = ENV['UNIT_TEST']
+ integrate_test = ENV['INTEGRATE_TEST']
+ path = Rails.root.join 'config/database.yml.example'
+ configs = YAML.load_file(path)
+ db_name = "#{configs[Rails.env]['database']}_#{unit_test && 'u_'}#{unit_test || integrate_test}"
+ configs[Rails.env]['database'] = db_name
+ File.open(path, 'w') {|f| YAML.dump(configs, f) }
end
- files = if unit_test # 4个并发
- unit_files.in_groups(parallel_size)[unit_test.to_i-1].join(' ')
- elsif integrate_test # 4个并发
- integrate_files.in_groups(parallel_size)[integrate_test.to_i-1].join(' ')
- end
- cmd = "rspec #{files}"
- #cmd = "rspec spec/requests/shop/shop_orders_spec.rb spec/requests/shop/shop_customers_spec.rb" # selenium-webdriver 2.14未清空session,按此顺序运行,第二个用例失败
- puts "Starting to run #{cmd}..."
- system("export DISPLAY=:99.0 && bundle exec #{cmd}")
- raise "#{cmd} failed!" unless $?.exitstatus == 0
+
+ desc "Run travis in parallel"
+ task :parallel do
+ parallel_size = 5
+ unit_test = ENV['UNIT_TEST']
+ integrate_test = ENV['INTEGRATE_TEST']
+ all_files = Dir.chdir(Rails.root) { Dir["spec/**/*_spec.rb"]}.sort
+ integrate_files = Dir.chdir(Rails.root) { Dir["spec/requests/**/*_spec.rb"]}.sort
+ unit_files = all_files - integrate_files
+ %w(shop/shops_searches_spec.rb lookup_spec.rb).each do |searchable_spec|
+ integrate_files.delete "spec/requests/#{searchable_spec}" # 需要solr才能运行
+ end
+ files = if unit_test # 7个并发
+ unit_files.in_groups(parallel_size)[unit_test.to_i-1].join(' ')
+ elsif integrate_test # 7个并发
+ integrate_files.in_groups(parallel_size)[integrate_test.to_i-1].join(' ')
+ end
+
+ cmd = "rspec #{files}"
+ #cmd = "rspec spec/requests/shop/shop_orders_spec.rb spec/requests/shop/shop_customers_spec.rb" # selenium-webdriver 2.14未清空session,按此顺序运行,第二个用例失败
+ puts "Starting to run #{cmd}..."
+ system("export DISPLAY=:99.0 && bundle exec #{cmd}")
+ raise "#{cmd} failed!" unless $?.exitstatus == 0
+ end
+
end
Shopqi::Application.load_tasks
View
10 config/database.yml.example
@@ -44,16 +44,6 @@ test:
username: postgres
password:
-#持续测试,travis-ci的服务器不允许host,username,password
-travis:
- adapter: postgresql
- encoding: unicode
- database: shopqi_test
- pool: 5
- #host: localhost
- #username: postgres
- #password:
-
production:
adapter: postgresql
encoding: unicode
Please sign in to comment.
Something went wrong with that request. Please try again.