From fd282f7d73afac246bd93b34fd9c516caf6d4d84 Mon Sep 17 00:00:00 2001 From: Fernando Briano Date: Fri, 27 Dec 2024 11:01:51 +0000 Subject: [PATCH] [CI] Handles mutex_m issue with Ruby 3.4 in tests --- Gemfile | 1 + spec/elastic/adapters/Gemfile | 29 +++++++++++ spec/elastic/adapters/adapters_tests.rake | 31 ++++++++++++ spec/elastic/adapters/excon.gemfile | 24 +++++++++ spec/elastic/adapters/excon_spec.rb | 62 +++++++++++++++++++++++ spec/elastic/transport/client_spec.rb | 1 + 6 files changed, 148 insertions(+) create mode 100644 spec/elastic/adapters/Gemfile create mode 100644 spec/elastic/adapters/adapters_tests.rake create mode 100644 spec/elastic/adapters/excon.gemfile create mode 100644 spec/elastic/adapters/excon_spec.rb diff --git a/Gemfile b/Gemfile index 113de35..b7fc136 100644 --- a/Gemfile +++ b/Gemfile @@ -22,6 +22,7 @@ gemspec group :development, :test do gem 'faraday-httpclient' + gem 'mutex_m' if RUBY_VERSION >= '3.4' gem 'faraday-net_http_persistent' gem 'faraday-typhoeus' gem 'faraday-excon' diff --git a/spec/elastic/adapters/Gemfile b/spec/elastic/adapters/Gemfile new file mode 100644 index 0000000..592ded6 --- /dev/null +++ b/spec/elastic/adapters/Gemfile @@ -0,0 +1,29 @@ +# Licensed to Elasticsearch B.V. under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +source 'https://rubygems.org' + +# $ BUNDLE_GEMFILE=./Gemfile-excon.gemfile bundle install +# $ BUNDLE_GEMFILE=./Gemfile-excon.gemfile bundle exec rake test:adapters +gemspec + +gem 'rspec' +gem 'elasticsearch' + +group :excon do + gem 'faraday-excon' +end diff --git a/spec/elastic/adapters/adapters_tests.rake b/spec/elastic/adapters/adapters_tests.rake new file mode 100644 index 0000000..857dbd4 --- /dev/null +++ b/spec/elastic/adapters/adapters_tests.rake @@ -0,0 +1,31 @@ +# Licensed to Elasticsearch B.V. under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +namespace :test do + namespace :adapters do + desc 'Run excon test' + task :excon do + # sh "BUNDLE_GEMFILE=#{FARADAY1_GEMFILE} bundle exec rspec" + # test.test_files = FileList[''] + # test.verbose = false + # test.warning = false + # sh "BUNDLE_GEMFILE=#{FARADAY1_GEMFILE} ruby -Ilib:test #{test}" + test = File.expand_path('./excon_spec.rb', __dir__) + sh "bundle exec rspec #{test}" + end + end +end diff --git a/spec/elastic/adapters/excon.gemfile b/spec/elastic/adapters/excon.gemfile new file mode 100644 index 0000000..3836820 --- /dev/null +++ b/spec/elastic/adapters/excon.gemfile @@ -0,0 +1,24 @@ +# Licensed to Elasticsearch B.V. under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +source 'https://rubygems.org' + +# $ BUNDLE_GEMFILE=./Gemfile-excon.gemfile bundle install +# $ BUNDLE_GEMFILE=./Gemfile-excon.gemfile bundle exec rake test:adapters +gemspec + +gem 'faraday-excon' diff --git a/spec/elastic/adapters/excon_spec.rb b/spec/elastic/adapters/excon_spec.rb new file mode 100644 index 0000000..6efdbfe --- /dev/null +++ b/spec/elastic/adapters/excon_spec.rb @@ -0,0 +1,62 @@ +# Licensed to Elasticsearch B.V. under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +require 'bundler/inline' +gemfile do + source 'https://rubygems.org' + + gem 'faraday-excon' + gem 'elasticsearch' + gem 'rspec' + gem 'debug' + gemspec +end + +require 'elasticsearch' +require 'faraday/excon' +require 'spec_helper' + +describe 'Excon Adapter' do + let(:client) do + Elasticsearch::Client.new( + hosts: ELASTICSEARCH_HOSTS, + adapter: :excon, + transport_options: { ssl: { verify: false } } + ) + end + + context 'Integrates with elasticsearch API' do + it 'should perform the API methods' do + expect do + # Index a document + client.index(index: 'test-index', id: '1', body: { title: 'Test' }) + + # Refresh the index + client.indices.refresh(index: 'test-index') + + # Search + response = client.search(index: 'test-index', body: { query: { match: { title: 'test' } } }) + + expect(response['hits']['total']['value']).to eq 1 + expect(response['hits']['hits'][0]['_source']['title']).to eq 'Test' + + # Delete the index + client.indices.delete(index: 'test-index') + end.not_to raise_error + end + end +end diff --git a/spec/elastic/transport/client_spec.rb b/spec/elastic/transport/client_spec.rb index a2a8143..be9eea5 100644 --- a/spec/elastic/transport/client_spec.rb +++ b/spec/elastic/transport/client_spec.rb @@ -1469,6 +1469,7 @@ context 'when using the HTTPClient adapter' do require 'faraday/httpclient' + require 'mutex_m' let(:client) do described_class.new(hosts: ELASTICSEARCH_HOSTS, compression: true, adapter: :httpclient, enable_meta_header: false)