Skip to content

Update test tasks and travis #840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ language: ruby

services:
- mongodb
- elasticsearch

branches:
only:
Expand All @@ -23,29 +24,40 @@ matrix:
include:
- rvm: 2.2
jdk: oraclejdk8
env: TEST_SUITE=unit
env: RAILS_VERSIONS=3.0

- rvm: 2.3
jdk: oraclejdk8
env: TEST_SUITE=unit
env: RAILS_VERSIONS=5.0

- rvm: 2.4
jdk: oraclejdk8
env: TEST_SUITE=unit
env: RAILS_VERSIONS=5.0

- rvm: 2.5
jdk: oraclejdk8
env: TEST_SUITE=unit
env: RAILS_VERSIONS=5.0

- rvm: jruby-9.1
jdk: oraclejdk8
env: TEST_SUITE=unit
env: RAILS_VERSIONS=5.0

- rvm: 2.5
jdk: oraclejdk8
env: TEST_SUITE=integration QUIET=y
env: RAILS_VERSIONS=4.0,5.0

env:
global:
- ELASTICSEARCH_VERSION=6.4.0
- QUIET=true


before_install:
- wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ELASTICSEARCH_VERSION}.deb
- wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ELASTICSEARCH_VERSION}.deb.sha512
- shasum -a 512 -c elasticsearch-${ELASTICSEARCH_VERSION}.deb.sha512
- sudo dpkg -i --force-confnew elasticsearch-${ELASTICSEARCH_VERSION}.deb
- sudo service elasticsearch restart
- gem update --system -q
- gem update bundler -q
- gem --version
Expand All @@ -57,7 +69,7 @@ install:
- rake bundle:install

script:
- rake test:$TEST_SUITE
- rake test:all

notifications:
disable: true
41 changes: 28 additions & 13 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'pathname'

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

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

Expand All @@ -25,15 +26,9 @@ namespace :bundle do
task :install do
subprojects.each do |project|
puts '-'*80
sh "bundle install --gemfile #{__current__.join(project)}/Gemfile"
sh "cd #{__current__.join(project)} && bundle exec rake bundle:install"
puts
end
puts '-'*80
sh "bundle install --gemfile #{__current__.join('elasticsearch-model/gemfiles')}/3.0.gemfile"
puts '-'*80
sh "bundle install --gemfile #{__current__.join('elasticsearch-model/gemfiles')}/4.0.gemfile"
puts '-'*80
sh "bundle install --gemfile #{__current__.join('elasticsearch-model/gemfiles')}/5.0.gemfile"
end

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

desc "Run Elasticsearch (Docker)"
task :setup_elasticsearch do
task :setup_elasticsearch_docker do
begin
sh <<-COMMAND.gsub(/^\s*/, '').gsub(/\s{1,}/, ' ')
docker run -d=true \
Expand All @@ -70,15 +65,30 @@ namespace :test do
--env "cluster.routing.allocation.disk.threshold_enabled=false" \
--publish 9250:9200 \
--rm \
docker.elastic.co/elasticsearch/elasticsearch:6.4.0
docker.elastic.co/elasticsearch/elasticsearch:${ELASTICSEARCH_VERSION}
COMMAND
require 'elasticsearch/extensions/test/cluster'
Elasticsearch::Extensions::Test::Cluster::Cluster.new(version: '6.4.0',
Elasticsearch::Extensions::Test::Cluster::Cluster.new(version: ENV['ELASTICSEARCH_VERSION'],
number_of_nodes: 1).wait_for_green
rescue
end
end

desc "Setup MongoDB (Docker)"
task :setup_mongodb_docker do
begin
if ENV['MONGODB_VERSION']
sh <<-COMMAND.gsub(/^\s*/, '').gsub(/\s{1,}/, ' ')
wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-${MONGODB_VERSION}.tgz -O /tmp/mongodb.tgz &&
tar -xvf /tmp/mongodb.tgz &&
mkdir /tmp/data &&
${PWD}/mongodb-linux-x86_64-${MONGODB_VERSION}/bin/mongod --setParameter enableTestCommands=1 --dbpath /tmp/data --bind_ip 127.0.0.1 --auth &> /dev/null &
COMMAND
end
rescue
end
end

desc "Run integration tests in all subprojects"
task :integration => :setup_elasticsearch do
# 1/ elasticsearch-model
Expand Down Expand Up @@ -106,8 +116,13 @@ namespace :test do

desc "Run all tests in all subprojects"
task :all do
Rake::Task['test:unit'].invoke
Rake::Task['test:integration'].invoke
subprojects.each do |project|
puts '-'*80
sh "cd #{project} && " +
"unset BUNDLE_GEMFILE && " +
"bundle exec rake test:all"
puts "\n"
end
end

namespace :cluster do
Expand Down
61 changes: 26 additions & 35 deletions elasticsearch-model/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,25 @@ desc "Run unit tests"
task :default => 'test:unit'
task :test => 'test:unit'

namespace :bundler do
desc "Install dependencies for all the Gemfiles"
if RUBY_VERSION < '2.3'
GEMFILES = ['3.0.gemfile', '4.0.gemfile', '5.0.gemfile']
else
GEMFILES = ['4.0.gemfile', '5.0.gemfile']
end

namespace :bundle do
desc 'Install dependencies for all the Gemfiles in /gemfiles. Optionally define env variable RAILS_VERSIONS. E.g. RAILS_VERSIONS=3.0,5.0'
task :install do
sh "BUNDLE_GEMFILE='#{File.expand_path('../gemfiles/3.0.gemfile', __FILE__)}' bundle install"
sh "BUNDLE_GEMFILE='#{File.expand_path('../gemfiles/4.0.gemfile', __FILE__)}' bundle install"
sh "BUNDLE_GEMFILE='#{File.expand_path('../gemfiles/5.0.gemfile', __FILE__)}' bundle install"
unless defined?(JRUBY_VERSION)
puts '-'*80
gemfiles = ENV['RAILS_VERSIONS'] ? ENV['RAILS_VERSIONS'].split(',').map { |v| "#{v}.gemfile"} : GEMFILES
gemfiles.each do |gemfile|
Bundler.with_clean_env do
sh "bundle install --gemfile #{File.expand_path('../gemfiles/'+gemfile, __FILE__)}"
end
puts '-'*80
end
end
end
end

Expand All @@ -18,38 +31,16 @@ end
require 'rake/testtask'
namespace :test do

Rake::TestTask.new(:run_unit) do |test|
test.libs << 'lib' << 'test'
test.test_files = FileList["test/unit/**/*_test.rb"]
test.verbose = false
test.warning = false
end

Rake::TestTask.new(:run_integration) do |test|
test.libs << 'lib' << 'test'
test.test_files = FileList["test/integration/**/*_test.rb"]
test.verbose = false
test.warning = false
end

desc "Run unit tests against ActiveModel 3, 4 and 5"
task :unit do
end

desc "Run integration tests against latest stable ActiveModel (5)"
task :integration do
['3.0.gemfile', '4.0.gemfile', '5.0.gemfile'].each do |gemfile|
['bundle exec rake test:run_unit', 'bundle exec rspec'].each do |cmd|
sh "BUNDLE_GEMFILE='#{File.expand_path('../gemfiles/'+gemfile, __FILE__)}' #{cmd}"
end
desc 'Run all tests. Optionally define env variable RAILS_VERSIONS. E.g. RAILS_VERSIONS=3.0,5.0'
task :all, [:rails_versions] do |task, args|
gemfiles = ENV['RAILS_VERSIONS'] ? ENV['RAILS_VERSIONS'].split(',').map {|v| "#{v}.gemfile"} : GEMFILES
puts '-' * 80
gemfiles.each do |gemfile|
sh "BUNDLE_GEMFILE='#{File.expand_path("../gemfiles/#{gemfile}", __FILE__)}' " +
" bundle exec rspec"
puts '-' * 80
end
end

desc "Run unit and integration tests"
task :all do
Rake::Task['test:unit'].invoke
Rake::Task['test:integration'].invoke
end
end

# ----- Documentation tasks ---------------------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion elasticsearch-model/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
require 'yaml'
require 'active_record'

unless defined?(ELASTICSEARCH_URL)
ELASTICSEARCH_URL = ENV['ELASTICSEARCH_URL'] || "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9200)}"
end

RSpec.configure do |config|
config.formatter = 'documentation'
config.color = true
Expand All @@ -18,7 +22,7 @@
require 'ansi'
tracer = ::Logger.new(STDERR)
tracer.formatter = lambda { |s, d, p, m| "#{m.gsub(/^.*$/) { |n| ' ' + n }.ansi(:faint)}\n" }
Elasticsearch::Model.client = Elasticsearch::Client.new host: "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9250)}",
Elasticsearch::Model.client = Elasticsearch::Client.new host: ELASTICSEARCH_URL,
tracer: (ENV['QUIET'] ? nil : tracer)

unless ActiveRecord::Base.connected?
Expand Down
17 changes: 10 additions & 7 deletions elasticsearch-persistence/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ require 'rspec/core/rake_task'
namespace :test do

RSpec::Core::RakeTask.new(:spec)
Rake::TestTask.new(:unit) do |test|
end

Rake::TestTask.new(:integration) do |test|
Rake::TestTask.new(:all) do |test|
test.verbose = false
test.warning = false
test.deps = [ :spec ]
end
end

Rake::TestTask.new(:all) do |test|
test.verbose = false
test.warning = false
test.deps = [ :spec ]
namespace :bundle do
desc 'Install gem dependencies'
task :install do
puts '-'*80
Bundler.with_clean_env do
sh 'bundle install'
end
puts '-'*80
end
end

Expand Down
6 changes: 5 additions & 1 deletion elasticsearch-persistence/spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
require 'pry-nav'
require 'elasticsearch/persistence'

unless defined?(ELASTICSEARCH_URL)
ELASTICSEARCH_URL = ENV['ELASTICSEARCH_URL'] || "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9200)}"
end

RSpec.configure do |config|
config.formatter = 'documentation'
config.color = true
Expand All @@ -13,7 +17,7 @@
# The default client to be used by the repositories.
#
# @since 6.0.0
DEFAULT_CLIENT = Elasticsearch::Client.new(host: "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9250)}",
DEFAULT_CLIENT = Elasticsearch::Client.new(host: ELASTICSEARCH_URL,
tracer: (ENV['QUIET'] ? nil : ::Logger.new(STDERR)))

class MyTestRepository
Expand Down
11 changes: 11 additions & 0 deletions elasticsearch-rails/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ namespace :test do
end
end

namespace :bundle do
desc 'Install gem dependencies'
task :install do
puts '-'*80
Bundler.with_clean_env do
sh 'bundle install'
end
puts '-'*80
end
end

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

require 'yard'
Expand Down
5 changes: 4 additions & 1 deletion elasticsearch-rails/test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
RUBY_1_8 = defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
unless defined?(ELASTICSEARCH_URL)
ELASTICSEARCH_URL = ENV['ELASTICSEARCH_URL'] || "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9200)}"
end

exit(0) if RUBY_1_8

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

Elasticsearch::Model.client = Elasticsearch::Client.new host: "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9250)}",
Elasticsearch::Model.client = Elasticsearch::Client.new host: ELASTICSEARCH_URL,
tracer: (ENV['QUIET'] ? nil : tracer)
end
end
Expand Down