Skip to content

Commit e590db9

Browse files
committed
Update test tasks and travis (elastic#840)
* [CI] Update Travis testing structure * [RAILS] Update test tasks * [STORE] Update test tasks * [MODEL] Update test tasks
1 parent e72e02c commit e590db9

File tree

8 files changed

+108
-65
lines changed

8 files changed

+108
-65
lines changed

.travis.yml

+19-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ language: ruby
1010

1111
services:
1212
- mongodb
13+
- elasticsearch
1314

1415
branches:
1516
only:
@@ -23,29 +24,40 @@ matrix:
2324
include:
2425
- rvm: 2.2
2526
jdk: oraclejdk8
26-
env: TEST_SUITE=unit
27+
env: RAILS_VERSIONS=3.0
2728

2829
- rvm: 2.3
2930
jdk: oraclejdk8
30-
env: TEST_SUITE=unit
31+
env: RAILS_VERSIONS=5.0
3132

3233
- rvm: 2.4
3334
jdk: oraclejdk8
34-
env: TEST_SUITE=unit
35+
env: RAILS_VERSIONS=5.0
3536

3637
- rvm: 2.5
3738
jdk: oraclejdk8
38-
env: TEST_SUITE=unit
39+
env: RAILS_VERSIONS=5.0
3940

4041
- rvm: jruby-9.1
4142
jdk: oraclejdk8
42-
env: TEST_SUITE=unit
43+
env: RAILS_VERSIONS=5.0
4344

4445
- rvm: 2.5
4546
jdk: oraclejdk8
46-
env: TEST_SUITE=integration QUIET=y
47+
env: RAILS_VERSIONS=4.0,5.0
48+
49+
env:
50+
global:
51+
- ELASTICSEARCH_VERSION=6.4.0
52+
- QUIET=true
53+
4754

4855
before_install:
56+
- wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ELASTICSEARCH_VERSION}.deb
57+
- wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ELASTICSEARCH_VERSION}.deb.sha512
58+
- shasum -a 512 -c elasticsearch-${ELASTICSEARCH_VERSION}.deb.sha512
59+
- sudo dpkg -i --force-confnew elasticsearch-${ELASTICSEARCH_VERSION}.deb
60+
- sudo service elasticsearch restart
4961
- gem update --system -q
5062
- gem update bundler -q
5163
- gem --version
@@ -57,7 +69,7 @@ install:
5769
- rake bundle:install
5870

5971
script:
60-
- rake test:$TEST_SUITE
72+
- rake test:all
6173

6274
notifications:
6375
disable: true

Rakefile

+28-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'pathname'
22

3-
subprojects = %w| elasticsearch-rails elasticsearch-persistence elasticsearch-model |
3+
subprojects = [ 'elasticsearch-rails', 'elasticsearch-persistence' ]
4+
subprojects << 'elasticsearch-model' unless defined?(JRUBY_VERSION)
45

56
__current__ = Pathname( File.expand_path('..', __FILE__) )
67

@@ -25,15 +26,9 @@ namespace :bundle do
2526
task :install do
2627
subprojects.each do |project|
2728
puts '-'*80
28-
sh "bundle install --gemfile #{__current__.join(project)}/Gemfile"
29+
sh "cd #{__current__.join(project)} && bundle exec rake bundle:install"
2930
puts
3031
end
31-
puts '-'*80
32-
sh "bundle install --gemfile #{__current__.join('elasticsearch-model/gemfiles')}/3.0.gemfile"
33-
puts '-'*80
34-
sh "bundle install --gemfile #{__current__.join('elasticsearch-model/gemfiles')}/4.0.gemfile"
35-
puts '-'*80
36-
sh "bundle install --gemfile #{__current__.join('elasticsearch-model/gemfiles')}/5.0.gemfile"
3732
end
3833

3934
desc "Remove Gemfile.lock in all subprojects"
@@ -60,7 +55,7 @@ namespace :test do
6055
end
6156

6257
desc "Run Elasticsearch (Docker)"
63-
task :setup_elasticsearch do
58+
task :setup_elasticsearch_docker do
6459
begin
6560
sh <<-COMMAND.gsub(/^\s*/, '').gsub(/\s{1,}/, ' ')
6661
docker run -d=true \
@@ -70,15 +65,30 @@ namespace :test do
7065
--env "cluster.routing.allocation.disk.threshold_enabled=false" \
7166
--publish 9250:9200 \
7267
--rm \
73-
docker.elastic.co/elasticsearch/elasticsearch:6.4.0
68+
docker.elastic.co/elasticsearch/elasticsearch:${ELASTICSEARCH_VERSION}
7469
COMMAND
7570
require 'elasticsearch/extensions/test/cluster'
76-
Elasticsearch::Extensions::Test::Cluster::Cluster.new(version: '6.4.0',
71+
Elasticsearch::Extensions::Test::Cluster::Cluster.new(version: ENV['ELASTICSEARCH_VERSION'],
7772
number_of_nodes: 1).wait_for_green
7873
rescue
7974
end
8075
end
8176

77+
desc "Setup MongoDB (Docker)"
78+
task :setup_mongodb_docker do
79+
begin
80+
if ENV['MONGODB_VERSION']
81+
sh <<-COMMAND.gsub(/^\s*/, '').gsub(/\s{1,}/, ' ')
82+
wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-${MONGODB_VERSION}.tgz -O /tmp/mongodb.tgz &&
83+
tar -xvf /tmp/mongodb.tgz &&
84+
mkdir /tmp/data &&
85+
${PWD}/mongodb-linux-x86_64-${MONGODB_VERSION}/bin/mongod --setParameter enableTestCommands=1 --dbpath /tmp/data --bind_ip 127.0.0.1 --auth &> /dev/null &
86+
COMMAND
87+
end
88+
rescue
89+
end
90+
end
91+
8292
desc "Run integration tests in all subprojects"
8393
task :integration => :setup_elasticsearch do
8494
# 1/ elasticsearch-model
@@ -106,8 +116,13 @@ namespace :test do
106116

107117
desc "Run all tests in all subprojects"
108118
task :all do
109-
Rake::Task['test:unit'].invoke
110-
Rake::Task['test:integration'].invoke
119+
subprojects.each do |project|
120+
puts '-'*80
121+
sh "cd #{project} && " +
122+
"unset BUNDLE_GEMFILE && " +
123+
"bundle exec rake test:all"
124+
puts "\n"
125+
end
111126
end
112127

113128
namespace :cluster do

elasticsearch-model/Rakefile

+26-35
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,25 @@ desc "Run unit tests"
44
task :default => 'test:unit'
55
task :test => 'test:unit'
66

7-
namespace :bundler do
8-
desc "Install dependencies for all the Gemfiles"
7+
if RUBY_VERSION < '2.3'
8+
GEMFILES = ['3.0.gemfile', '4.0.gemfile', '5.0.gemfile']
9+
else
10+
GEMFILES = ['4.0.gemfile', '5.0.gemfile']
11+
end
12+
13+
namespace :bundle do
14+
desc 'Install dependencies for all the Gemfiles in /gemfiles. Optionally define env variable RAILS_VERSIONS. E.g. RAILS_VERSIONS=3.0,5.0'
915
task :install do
10-
sh "BUNDLE_GEMFILE='#{File.expand_path('../gemfiles/3.0.gemfile', __FILE__)}' bundle install"
11-
sh "BUNDLE_GEMFILE='#{File.expand_path('../gemfiles/4.0.gemfile', __FILE__)}' bundle install"
12-
sh "BUNDLE_GEMFILE='#{File.expand_path('../gemfiles/5.0.gemfile', __FILE__)}' bundle install"
16+
unless defined?(JRUBY_VERSION)
17+
puts '-'*80
18+
gemfiles = ENV['RAILS_VERSIONS'] ? ENV['RAILS_VERSIONS'].split(',').map { |v| "#{v}.gemfile"} : GEMFILES
19+
gemfiles.each do |gemfile|
20+
Bundler.with_clean_env do
21+
sh "bundle install --gemfile #{File.expand_path('../gemfiles/'+gemfile, __FILE__)}"
22+
end
23+
puts '-'*80
24+
end
25+
end
1326
end
1427
end
1528

@@ -18,38 +31,16 @@ end
1831
require 'rake/testtask'
1932
namespace :test do
2033

21-
Rake::TestTask.new(:run_unit) do |test|
22-
test.libs << 'lib' << 'test'
23-
test.test_files = FileList["test/unit/**/*_test.rb"]
24-
test.verbose = false
25-
test.warning = false
26-
end
27-
28-
Rake::TestTask.new(:run_integration) do |test|
29-
test.libs << 'lib' << 'test'
30-
test.test_files = FileList["test/integration/**/*_test.rb"]
31-
test.verbose = false
32-
test.warning = false
33-
end
34-
35-
desc "Run unit tests against ActiveModel 3, 4 and 5"
36-
task :unit do
37-
end
38-
39-
desc "Run integration tests against latest stable ActiveModel (5)"
40-
task :integration do
41-
['3.0.gemfile', '4.0.gemfile', '5.0.gemfile'].each do |gemfile|
42-
['bundle exec rake test:run_unit', 'bundle exec rspec'].each do |cmd|
43-
sh "BUNDLE_GEMFILE='#{File.expand_path('../gemfiles/'+gemfile, __FILE__)}' #{cmd}"
44-
end
34+
desc 'Run all tests. Optionally define env variable RAILS_VERSIONS. E.g. RAILS_VERSIONS=3.0,5.0'
35+
task :all, [:rails_versions] do |task, args|
36+
gemfiles = ENV['RAILS_VERSIONS'] ? ENV['RAILS_VERSIONS'].split(',').map {|v| "#{v}.gemfile"} : GEMFILES
37+
puts '-' * 80
38+
gemfiles.each do |gemfile|
39+
sh "BUNDLE_GEMFILE='#{File.expand_path("../gemfiles/#{gemfile}", __FILE__)}' " +
40+
" bundle exec rspec"
41+
puts '-' * 80
4542
end
4643
end
47-
48-
desc "Run unit and integration tests"
49-
task :all do
50-
Rake::Task['test:unit'].invoke
51-
Rake::Task['test:integration'].invoke
52-
end
5344
end
5445

5546
# ----- Documentation tasks ---------------------------------------------------

elasticsearch-model/spec/spec_helper.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
require 'yaml'
1111
require 'active_record'
1212

13+
unless defined?(ELASTICSEARCH_URL)
14+
ELASTICSEARCH_URL = ENV['ELASTICSEARCH_URL'] || "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9200)}"
15+
end
16+
1317
RSpec.configure do |config|
1418
config.formatter = 'documentation'
1519
config.color = true
@@ -18,7 +22,7 @@
1822
require 'ansi'
1923
tracer = ::Logger.new(STDERR)
2024
tracer.formatter = lambda { |s, d, p, m| "#{m.gsub(/^.*$/) { |n| ' ' + n }.ansi(:faint)}\n" }
21-
Elasticsearch::Model.client = Elasticsearch::Client.new host: "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9250)}",
25+
Elasticsearch::Model.client = Elasticsearch::Client.new host: ELASTICSEARCH_URL,
2226
tracer: (ENV['QUIET'] ? nil : tracer)
2327

2428
unless ActiveRecord::Base.connected?

elasticsearch-persistence/Rakefile

+10-7
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,22 @@ require 'rspec/core/rake_task'
1212
namespace :test do
1313

1414
RSpec::Core::RakeTask.new(:spec)
15-
Rake::TestTask.new(:unit) do |test|
16-
end
1715

18-
Rake::TestTask.new(:integration) do |test|
16+
Rake::TestTask.new(:all) do |test|
1917
test.verbose = false
2018
test.warning = false
2119
test.deps = [ :spec ]
2220
end
21+
end
2322

24-
Rake::TestTask.new(:all) do |test|
25-
test.verbose = false
26-
test.warning = false
27-
test.deps = [ :spec ]
23+
namespace :bundle do
24+
desc 'Install gem dependencies'
25+
task :install do
26+
puts '-'*80
27+
Bundler.with_clean_env do
28+
sh 'bundle install'
29+
end
30+
puts '-'*80
2831
end
2932
end
3033

elasticsearch-persistence/spec/spec_helper.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
require 'pry-nav'
22
require 'elasticsearch/persistence'
33

4+
unless defined?(ELASTICSEARCH_URL)
5+
ELASTICSEARCH_URL = ENV['ELASTICSEARCH_URL'] || "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9200)}"
6+
end
7+
48
RSpec.configure do |config|
59
config.formatter = 'documentation'
610
config.color = true
@@ -13,7 +17,7 @@
1317
# The default client to be used by the repositories.
1418
#
1519
# @since 6.0.0
16-
DEFAULT_CLIENT = Elasticsearch::Client.new(host: "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9250)}",
20+
DEFAULT_CLIENT = Elasticsearch::Client.new(host: ELASTICSEARCH_URL,
1721
tracer: (ENV['QUIET'] ? nil : ::Logger.new(STDERR)))
1822

1923
class MyTestRepository

elasticsearch-rails/Rakefile

+11
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ namespace :test do
2828
end
2929
end
3030

31+
namespace :bundle do
32+
desc 'Install gem dependencies'
33+
task :install do
34+
puts '-'*80
35+
Bundler.with_clean_env do
36+
sh 'bundle install'
37+
end
38+
puts '-'*80
39+
end
40+
end
41+
3142
# ----- Documentation tasks ---------------------------------------------------
3243

3344
require 'yard'

elasticsearch-rails/test/test_helper.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
RUBY_1_8 = defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
2+
unless defined?(ELASTICSEARCH_URL)
3+
ELASTICSEARCH_URL = ENV['ELASTICSEARCH_URL'] || "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9200)}"
4+
end
25

36
exit(0) if RUBY_1_8
47

@@ -56,7 +59,7 @@ def setup
5659
tracer = ::Logger.new(STDERR)
5760
tracer.formatter = lambda { |s, d, p, m| "#{m.gsub(/^.*$/) { |n| ' ' + n }.ansi(:faint)}\n" }
5861

59-
Elasticsearch::Model.client = Elasticsearch::Client.new host: "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9250)}",
62+
Elasticsearch::Model.client = Elasticsearch::Client.new host: ELASTICSEARCH_URL,
6063
tracer: (ENV['QUIET'] ? nil : tracer)
6164
end
6265
end

0 commit comments

Comments
 (0)