forked from saberma/shopqi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
52 lines (44 loc) · 2.26 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
require 'rake'
require 'resque/tasks'
require 'resque_scheduler/tasks'
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
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'
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
desc "Run travis in parallel"
task :parallel do
parallel_size = 8
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 # 8个并发
unit_files.in_groups(parallel_size)[unit_test.to_i-1].join(' ')
elsif integrate_test # 8个并发
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