Skip to content

Satisfy all tests on 8.x branch #1075

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

Open
wants to merge 7 commits into
base: 8.x
Choose a base branch
from
Open
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
18 changes: 10 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ def admin_client

if test_suite == 'security'
transport_options.merge!(:ssl => { verify: false,
ca_path: CERT_DIR })
ca_path: defined?(CERT_DIR) ? CERT_DIR : nil
}.compact)

password = ENV['ELASTIC_PASSWORD']
user = ENV['ELASTIC_USER'] || 'elastic'
url = "https://#{user}:#{password}@#{host}:#{port}"
url = "https://#{user}:#{password}@#{host || 'localhost'}:#{port || 9200}"
else
url = "http://#{host || 'localhost'}:#{port || 9200}"
end
ENV['ELASTICSEARCH_URL'] ||= url
Elasticsearch::Client.new(host: url, transport_options: transport_options)
end
end
Expand Down Expand Up @@ -140,7 +142,7 @@ namespace :test do
end

desc "Run all tests in all subprojects"
task all: :wait_for_green do
task all: :wait_for_green_or_yellow do
subprojects.each do |project|
puts '-'*80
sh "cd #{project} && " +
Expand All @@ -151,20 +153,20 @@ namespace :test do
end
end

desc "Wait for elasticsearch cluster to be in green state"
task :wait_for_green do
desc "Wait for elasticsearch cluster to be in green or yellow state"
task :wait_for_green_or_yellow do
require 'elasticsearch'

ready = nil
5.times do |i|
begin
puts "Attempting to wait for green status: #{i + 1}"
if admin_client.cluster.health(wait_for_status: 'green', timeout: '50s')
puts "Attempting to wait for green or yellow status: #{i + 1}"
if admin_client.cluster.health(wait_for_status: 'yellow', timeout: '50s')
ready = true
break
end
rescue Elastic::Transport::Transport::Errors::RequestTimeout => ex
puts "Couldn't confirm green status.\n#{ex.inspect}."
puts "Couldn't confirm green or yellow status.\n#{ex.inspect}."
rescue Faraday::ConnectionFailed => ex
puts "Couldn't connect to Elasticsearch.\n#{ex.inspect}."
sleep(30)
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch-model/lib/elasticsearch/model/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def initialize(target)
@target = target
end

def ruby2_keywords(*) # :nodoc:
def self.ruby2_keywords(*) # :nodoc:
end if RUBY_VERSION < "2.7"

# Delegate methods to `@target`. As per [the Ruby 3.0 explanation for keyword arguments](https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/), the only way to work on Ruby <2.7, and 2.7, and 3.0+ is to use `ruby2_keywords`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
it 'imports all documents' do
expect(ImportArticle.search('*').results.total).to eq(10)
end

it "does not pollute the model's namespace" do
expect(ImportArticle.methods).not_to include(:__transform)
end
end

context 'when batch size is specified' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ class ::DummyIndexingModelForRecreate

context 'when the index is not found' do
let(:logger) { nil }
let(:client) { Elasticsearch::Client.new(logger: logger) }
let(:client) { Elasticsearch::Client.new(logger: logger, transport_options: { ssl: { verify: false } }) }

before do
expect(DummyIndexingModelForRecreate).to receive(:client).at_most(3).times.and_return(client)
Expand Down
7 changes: 6 additions & 1 deletion elasticsearch-model/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
require 'yaml'
require 'active_record'

# Load all of ActiveSupport to be sure of complete compatibility -
# see https://github.com/elastic/elasticsearch-rails/pull/1075 for details
require 'active_support/all'

unless defined?(ELASTICSEARCH_URL)
ELASTICSEARCH_URL = ENV['ELASTICSEARCH_URL'] || "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9200)}"
end
Expand All @@ -45,7 +49,8 @@
tracer.formatter = lambda { |s, d, p, m| "#{m.gsub(/^.*$/) { |n| ' ' + n }.ansi(:faint)}\n" }
Elasticsearch::Model.client = Elasticsearch::Client.new(
host: ELASTICSEARCH_URL,
tracer: (ENV['QUIET'] ? nil : tracer)
tracer: (ENV['QUIET'] ? nil : tracer),
transport_options: { :ssl => { verify: false } }
)
puts "Elasticsearch Version: #{Elasticsearch::Model.client.info['version']}"

Expand Down
3 changes: 2 additions & 1 deletion elasticsearch-persistence/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
#
# @since 6.0.0
DEFAULT_CLIENT = Elasticsearch::Client.new(host: ELASTICSEARCH_URL,
tracer: (ENV['QUIET'] ? nil : ::Logger.new(STDERR)))
tracer: (ENV['QUIET'] ? nil : ::Logger.new(STDERR)),
transport_options: { :ssl => { verify: false } })

class MyTestRepository
include Elasticsearch::Persistence::Repository
Expand Down
3 changes: 2 additions & 1 deletion elasticsearch-rails/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
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: ELASTICSEARCH_URL,
tracer: (ENV['QUIET'] ? nil : tracer)
tracer: (ENV['QUIET'] ? nil : tracer),
transport_options: { :ssl => { verify: false } }
puts "Elasticsearch Version: #{Elasticsearch::Model.client.info['version']}"

unless ActiveRecord::Base.connected?
Expand Down
Loading