From dd093c0a91f68d583f062c11ca3d7b0f35eb0e41 Mon Sep 17 00:00:00 2001 From: Sergey Avseyev Date: Thu, 18 Jul 2024 15:51:34 -0700 Subject: [PATCH] fix tests on 7.6 --- .github/workflows/tests.yml | 18 -------- lib/active_support/cache/couchbase_store.rb | 3 +- .../behaviors/local_cache_behavior.rb | 3 ++ test/crud_test.rb | 2 +- test/ds_map_test.rb | 6 +-- test/query_index_manager_test.rb | 4 ++ test/search_test.rb | 45 ++++++++++++++++++- test/subdoc_test.rb | 16 ++++++- test/test_helper.rb | 25 ++++++++++- test/utils/consistency_helper.rb | 9 ++++ 10 files changed, 100 insertions(+), 31 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 71fcb7fc..4b2a57db 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -135,7 +135,6 @@ jobs: fail-fast: false matrix: ruby: - - '3.0' - '3.1' - '3.2' - '3.3' @@ -174,10 +173,6 @@ jobs: - uses: actions/download-artifact@v4 with: name: scripts-${{ needs.source.outputs.gem_version }} - - uses: actions/download-artifact@v4 - with: - path: pkg/binary/3.0 - name: couchbase-${{ needs.source.outputs.gem_version }}-x86_64-linux-3.0 - uses: actions/download-artifact@v4 with: path: pkg/binary/3.1 @@ -209,7 +204,6 @@ jobs: fail-fast: false matrix: ruby: - - '3.0' - '3.1' - '3.2' - '3.3' @@ -248,10 +242,6 @@ jobs: - uses: actions/download-artifact@v4 with: name: scripts-${{ needs.source.outputs.gem_version }} - - uses: actions/download-artifact@v4 - with: - path: pkg/binary/3.0 - name: couchbase-${{ needs.source.outputs.gem_version }}-arm64-darwin-3.0 - uses: actions/download-artifact@v4 with: path: pkg/binary/3.1 @@ -283,7 +273,6 @@ jobs: fail-fast: false matrix: ruby: - - '3.0' - '3.1' - '3.2' - '3.3' @@ -322,10 +311,6 @@ jobs: - uses: actions/download-artifact@v4 with: name: scripts-${{ needs.source.outputs.gem_version }} - - uses: actions/download-artifact@v4 - with: - path: pkg/binary/3.0 - name: couchbase-${{ needs.source.outputs.gem_version }}-x86_64-darwin-3.0 - uses: actions/download-artifact@v4 with: path: pkg/binary/3.1 @@ -360,7 +345,6 @@ jobs: fail-fast: false matrix: ruby: - - '3.0' - '3.1' - '3.2' - '3.3' @@ -421,7 +405,6 @@ jobs: fail-fast: false matrix: ruby: - - '3.0' - '3.1' - '3.2' - '3.3' @@ -485,7 +468,6 @@ jobs: fail-fast: false matrix: ruby: - - '3.0' - '3.1' - '3.2' - '3.3' diff --git a/lib/active_support/cache/couchbase_store.rb b/lib/active_support/cache/couchbase_store.rb index bd547222..607d81a0 100644 --- a/lib/active_support/cache/couchbase_store.rb +++ b/lib/active_support/cache/couchbase_store.rb @@ -108,7 +108,8 @@ def delete_matched(matcher, _options = nil) operation_options = ::Couchbase::Options::Query(named_parameters: {"pattern" => pattern}, metrics: true) operation_options.consistent_with(::Couchbase::MutationState.new(@last_mutation_token)) if @last_mutation_token begin - result = cluster.query("DELETE FROM #{scope_qualifier} cache WHERE REGEXP_MATCHES(META(cache).id, $pattern)", operation_options) + result = cluster.query("DELETE FROM #{scope_qualifier} cache_store_ WHERE REGEXP_MATCHES(META(cache_store_).id, $pattern)", + operation_options) result.meta_data.metrics.mutation_count rescue ::Couchbase::Error::ParsingFailure, ::Couchbase::Error::ServiceNotAvailable raise NotImplementedError, "The server does not support delete_matched operation" diff --git a/test/active_support/behaviors/local_cache_behavior.rb b/test/active_support/behaviors/local_cache_behavior.rb index e54e0d4f..594d2f6c 100644 --- a/test/active_support/behaviors/local_cache_behavior.rb +++ b/test/active_support/behaviors/local_cache_behavior.rb @@ -151,6 +151,9 @@ def test_local_cache_of_delete_matched skip("#{name}: The #{Couchbase::Protostellar::NAME} protocol does not support consistent_with yet") if env.protostellar? skip("#{name}: delete_matched is not stable on 6.x servers, version=#{env.server_version}") if use_caves? || env.server_version.mad_hatter? + + ensure_primary_index! + begin @cache.delete_matched("*") rescue NotImplementedError diff --git a/test/crud_test.rb b/test/crud_test.rb index eb846df8..42672ae8 100644 --- a/test/crud_test.rb +++ b/test/crud_test.rb @@ -57,7 +57,7 @@ def test_reads_from_replica doc_id = uniq_id(:foo) document = {"value" => 42} options = - if env.jenkins? + if env.jenkins? || use_caves? Options::Upsert(persist_to: :active, replicate_to: :one) else Options::Upsert(persist_to: :active) diff --git a/test/ds_map_test.rb b/test/ds_map_test.rb index 673a0580..54432baa 100644 --- a/test/ds_map_test.rb +++ b/test/ds_map_test.rb @@ -129,11 +129,7 @@ def test_changes_the_value_by_key refute_empty map map["baz"] = "bar" - pairs = map.map do |*pair| - pair - end - - assert_equal [%w[baz bar], ["foo", 100]], pairs.sort + assert_equal [%w[baz bar], ["foo", 100]], map.entries.sort end def test_removes_key diff --git a/test/query_index_manager_test.rb b/test/query_index_manager_test.rb index 891c765c..2a11b417 100644 --- a/test/query_index_manager_test.rb +++ b/test/query_index_manager_test.rb @@ -22,6 +22,8 @@ class QueryIndexManagerTest < Minitest::Test include TestUtilities def setup + return if use_caves? + connect @bucket_name = 'query-idx-test-bucket' @cluster.buckets.create_bucket( @@ -47,6 +49,8 @@ def setup end def teardown + return if use_caves? + @cluster.buckets.drop_bucket(@bucket_name) disconnect end diff --git a/test/search_test.rb b/test/search_test.rb index c844f86f..5700931d 100644 --- a/test/search_test.rb +++ b/test/search_test.rb @@ -21,10 +21,9 @@ class SearchTest < Minitest::Test include TestUtilities def setup - skip("#{name}: The #{Couchbase::Protostellar::NAME} protocol does not support search index management yet") if env.protostellar? + return if use_caves? connect - skip("#{name}: CAVES does not support query service yet") if use_caves? @bucket = @cluster.bucket(env.bucket) @scope = @bucket.default_scope @collection = @bucket.default_collection @@ -72,10 +71,16 @@ def setup end def teardown + return if use_caves? + + @cluster.search_indexes.drop_index(@index_name) disconnect end def test_simple_search + skip("#{name}: The #{Couchbase::Protostellar::NAME} protocol does not support search index management yet") if env.protostellar? + skip("#{name}: CAVES does not support search service yet") if use_caves? + doc_id = uniq_id(:foo) res = @collection.insert(doc_id, {"type" => "character", "name" => "Arthur"}) mutation_state = MutationState.new(res.mutation_token) @@ -108,6 +113,9 @@ def test_simple_search end def test_doc_id_search_query + skip("#{name}: The #{Couchbase::Protostellar::NAME} protocol does not support search index management yet") if env.protostellar? + skip("#{name}: CAVES does not support search service yet") if use_caves? + doc_ids = [uniq_id(:foo), uniq_id(:bar)] res1 = @collection.insert(doc_ids[0], {"type" => "character", "name" => "Arthur"}) res2 = @collection.insert(doc_ids[1], {"type" => "character", "name" => "Brodie"}) @@ -145,6 +153,9 @@ def test_doc_id_search_query end def test_search_request_backend_encoding + skip("#{name}: The #{Couchbase::Protostellar::NAME} protocol does not support search index management yet") if env.protostellar? + skip("#{name}: CAVES does not support search service yet") if use_caves? + vec1 = [-0.00810323283, 0.0727998167, 0.0211895034, -0.0254271757] vec2 = [-0.005610323283, 0.023427998167, 0.0132511895034, 0.03466271757] @@ -200,6 +211,9 @@ def test_search_request_backend_encoding end def test_search_request_invalid_argument + skip("#{name}: The #{Couchbase::Protostellar::NAME} protocol does not support search index management yet") if env.protostellar? + skip("#{name}: CAVES does not support search service yet") if use_caves? + vec1 = [-0.00810323283, 0.0727998167, 0.0211895034, -0.0254271757] vec2 = [-0.005610323283, 0.023427998167, 0.0132511895034, 0.03466271757] @@ -223,24 +237,36 @@ def test_search_request_invalid_argument end def test_vector_query_empty + skip("#{name}: The #{Couchbase::Protostellar::NAME} protocol does not support search index management yet") if env.protostellar? + skip("#{name}: CAVES does not support search service yet") if use_caves? + vector_query = VectorQuery.new("foo", []) assert_raises(Error::InvalidArgument) { vector_query.to_json } end def test_base64_vector_query_empty + skip("#{name}: The #{Couchbase::Protostellar::NAME} protocol does not support search index management yet") if env.protostellar? + skip("#{name}: CAVES does not support search service yet") if use_caves? + vector_query = VectorQuery.new("foo", "") assert_raises(Error::InvalidArgument) { vector_query.to_json } end def test_vector_query_nil + skip("#{name}: The #{Couchbase::Protostellar::NAME} protocol does not support search index management yet") if env.protostellar? + skip("#{name}: CAVES does not support search service yet") if use_caves? + vector_query = VectorQuery.new("foo", nil) assert_raises(Error::InvalidArgument) { vector_query.to_json } end def test_vector_query_invalid_candidate_number + skip("#{name}: The #{Couchbase::Protostellar::NAME} protocol does not support search index management yet") if env.protostellar? + skip("#{name}: CAVES does not support search service yet") if use_caves? + vector_query = VectorQuery.new("foo", [-1.1, 1.2]) do |q| q.num_candidates = 0 end @@ -251,6 +277,9 @@ def test_vector_query_invalid_candidate_number end def test_vector_search_empty_vector_query_array + skip("#{name}: The #{Couchbase::Protostellar::NAME} protocol does not support search index management yet") if env.protostellar? + skip("#{name}: CAVES does not support search service yet") if use_caves? + vector_search = VectorSearch.new([]) assert_raises(Error::InvalidArgument) do @@ -259,6 +288,9 @@ def test_vector_search_empty_vector_query_array end def test_vector_search_query_defaults_to_match_none + skip("#{name}: The #{Couchbase::Protostellar::NAME} protocol does not support search index management yet") if env.protostellar? + skip("#{name}: CAVES does not support search service yet") if use_caves? + vector_search = VectorSearch.new(VectorQuery.new("foo", [-1.1, 1.2])) enc_query, = SearchRequest.new(vector_search).to_backend @@ -266,6 +298,9 @@ def test_vector_search_query_defaults_to_match_none end def test_vector_search_query_base64 + skip("#{name}: The #{Couchbase::Protostellar::NAME} protocol does not support search index management yet") if env.protostellar? + skip("#{name}: CAVES does not support search service yet") if use_caves? + base64_query = "aOeYBEXJ4kI=" enc_vector_query = VectorQuery.new("foo", base64_query).to_h @@ -275,6 +310,9 @@ def test_vector_search_query_base64 end def test_vector_search_not_supported + skip("#{name}: The #{Couchbase::Protostellar::NAME} protocol does not support search index management yet") if env.protostellar? + skip("#{name}: CAVES does not support search service yet") if use_caves? + skip("#{name}: Server supports vector search") if !env.protostellar? && env.server_version.supports_vector_search? req = SearchRequest.new(VectorSearch.new(VectorQuery.new("foo", [-1.1, 1.2]))) @@ -284,6 +322,9 @@ def test_vector_search_not_supported end def test_scope_search_not_supported + skip("#{name}: The #{Couchbase::Protostellar::NAME} protocol does not support search index management yet") if env.protostellar? + skip("#{name}: CAVES does not support search service yet") if use_caves? + skip("#{name}: Server supports scope search") if !env.protostellar? && env.server_version.supports_scoped_search_indexes? req = SearchRequest.new(SearchQuery.match_all) diff --git a/test/subdoc_test.rb b/test/subdoc_test.rb index d9dfba8f..8b6b5e4f 100644 --- a/test/subdoc_test.rb +++ b/test/subdoc_test.rb @@ -359,7 +359,9 @@ def test_macros end def test_mad_hatter_macros - skip("The server does not support MadHatter macros (#{env.server_version})") unless env.server_version.mad_hatter? + unless env.server_version.supports_mad_hatter_subdoc_macros? + skip("The server does not support MadHatter macros (#{env.server_version})") + end doc_id = uniq_id(:foo) @@ -1272,7 +1274,17 @@ def test_multiple_xattr_keys_should_fail options = Collection::MutateInOptions.new options.store_semantics = :upsert - assert_raises env.protostellar? ? Error::InvalidArgument : Error::XattrInvalidKeyCombo do + exception_check = + if env.server_version.supports_multiple_xattr_keys_mutation? + lambda { |&block| block.call } + elsif env.protostellar? + # FIXME: most likely Protostellar/7.6.0+ will not not fail too + lambda { |&block| assert_raises(Error::InvalidArgument) { block.call } } + else + lambda { |&block| assert_raises(Error::XattrInvalidKeyCombo) { block.call } } + end + + exception_check.call do @collection.mutate_in(doc_id, [ MutateInSpec.increment("count", 1).xattr.create_path, MutateInSpec.insert("logs", "bar1").xattr.create_path, diff --git a/test/test_helper.rb b/test/test_helper.rb index 8fd640af..eae5c41c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -93,6 +93,10 @@ def supports_preserve_expiry? cheshire_cat? end + def supports_mad_hatter_subdoc_macros? + mad_hatter? || cheshire_cat? + end + def is_rcbc_408_applicable? @version < Gem::Version.create("7.0.0") end @@ -128,6 +132,10 @@ def supports_scoped_search_indexes? def supports_vector_search? trinity? end + + def supports_multiple_xattr_keys_mutation? + trinity? + end end require "couchbase" @@ -164,7 +172,15 @@ def bucket end def management_endpoint - @management_endpoint = ENV.fetch("TEST_MANAGEMENT_ENDPOINT", nil) + @management_endpoint = ENV.fetch("TEST_MANAGEMENT_ENDPOINT") do + if connection_string + parsed = Couchbase::Backend.parse_connection_string(connection_string) + first_node_address = parsed[:nodes].first[:address] + scheme = parsed[:tls] ? "https" : "http" + port = parsed[:tls] ? 18091 : 8091 + "#{scheme}://#{first_node_address}:#{port}" + end + end end def jenkins? @@ -188,7 +204,12 @@ def protostellar? end def consistency - @consistency ||= TestUtilities::ConsistencyHelper.new(management_endpoint, username, password) + @consistency ||= + if ENV.fetch("TEST_CONNECTION_STRING", nil) + TestUtilities::ConsistencyHelper.new(management_endpoint, username, password) + else + TestUtilities::MockConsistencyHelper.new + end end end diff --git a/test/utils/consistency_helper.rb b/test/utils/consistency_helper.rb index 9f780908..6e1d99a7 100644 --- a/test/utils/consistency_helper.rb +++ b/test/utils/consistency_helper.rb @@ -19,6 +19,15 @@ module Couchbase module TestUtilities + # CAVES does not support management API, but fast enough to be consistent + class MockConsistencyHelper < BasicObject + def method_missing(*); end + + def respond_to_missing?(*) + true + end + end + class ConsistencyHelper attr_reader :management_hosts