Skip to content

Commit

Permalink
fix tests on 7.6
Browse files Browse the repository at this point in the history
  • Loading branch information
avsej committed Jul 19, 2024
1 parent 8300ae9 commit dd093c0
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 31 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ jobs:
fail-fast: false
matrix:
ruby:
- '3.0'
- '3.1'
- '3.2'
- '3.3'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -209,7 +204,6 @@ jobs:
fail-fast: false
matrix:
ruby:
- '3.0'
- '3.1'
- '3.2'
- '3.3'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -283,7 +273,6 @@ jobs:
fail-fast: false
matrix:
ruby:
- '3.0'
- '3.1'
- '3.2'
- '3.3'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -360,7 +345,6 @@ jobs:
fail-fast: false
matrix:
ruby:
- '3.0'
- '3.1'
- '3.2'
- '3.3'
Expand Down Expand Up @@ -421,7 +405,6 @@ jobs:
fail-fast: false
matrix:
ruby:
- '3.0'
- '3.1'
- '3.2'
- '3.3'
Expand Down Expand Up @@ -485,7 +468,6 @@ jobs:
fail-fast: false
matrix:
ruby:
- '3.0'
- '3.1'
- '3.2'
- '3.3'
Expand Down
3 changes: 2 additions & 1 deletion lib/active_support/cache/couchbase_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions test/active_support/behaviors/local_cache_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/crud_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions test/ds_map_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/query_index_manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -47,6 +49,8 @@ def setup
end

def teardown
return if use_caves?

@cluster.buckets.drop_bucket(@bucket_name)
disconnect
end
Expand Down
45 changes: 43 additions & 2 deletions test/search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"})
Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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]

Expand All @@ -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
Expand All @@ -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
Expand All @@ -259,13 +288,19 @@ 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

assert_equal SearchQuery.match_none.to_json, enc_query
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

Expand All @@ -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])))
Expand All @@ -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)
Expand Down
16 changes: 14 additions & 2 deletions test/subdoc_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand Down
25 changes: 23 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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?
Expand All @@ -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

Expand Down
9 changes: 9 additions & 0 deletions test/utils/consistency_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit dd093c0

Please sign in to comment.