Skip to content

Commit 6ffed65

Browse files
authored
RUBY-3111 Fix test failures in BSON master cause by the changing of the Illegal Key error (#2617)
* RUBY-3111 Fix test failures in BSON master cause by the changing of the Illegal Key error * RUBY-3111 add min server version on retryable_writes_test * RUBY-3111 change to 4.4+
1 parent 5e7d71e commit 6ffed65

File tree

6 files changed

+37
-5
lines changed

6 files changed

+37
-5
lines changed

spec/integration/retryable_writes_errors_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
context "when encountering a NoWritesPerformed error after an error with a RetryableWriteError label" do
3636
require_topology :replica_set
3737
require_fail_command
38+
min_server_version '4.4'
3839

3940
let(:failpoint1) do
4041
{

spec/mongo/protocol/caching_hash_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
end
3737

3838
describe "#needs_validation?" do
39+
max_bson_version "4.99.99"
3940

4041
before do
4142
hash.to_bson(BSON::ByteBuffer.new, validation)

spec/mongo/protocol/msg_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@
390390
end
391391

392392
context 'when the validating_keys option is true with payload 1' do
393+
max_bson_version '4.99.99'
393394

394395
let(:sequences) do
395396
[ section ]

spec/runners/transactions/operation.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ def execute(target, context)
7373
'exception' => e,
7474
'error' => true,
7575
}
76-
# We do not have a base class for client side BSON-related errors.
77-
# See https://jira.mongodb.org/browse/RUBY-1806.
78-
# Rescue this particular exception for the time being.
79-
rescue BSON::String::IllegalKey => e
76+
rescue bson_error => e
8077
{
8178
'exception' => e,
8279
'clientError' => true,
@@ -323,6 +320,15 @@ def wait_for_primary_change(client, context)
323320
end
324321
end
325322
end
323+
324+
# The error to rescue BSON tests for. If we still define
325+
# BSON::String::IllegalKey then we should rescue that particular error,
326+
# otherwise, rescue an arbitrary BSON::Error
327+
def bson_error
328+
BSON::String.const_defined?(:IllegalKey) ?
329+
BSON::String.const_get(:IllegalKey) :
330+
BSON::Error
331+
end
326332
end
327333
end
328334
end

spec/runners/unified/test.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def execute_operation(op)
395395
end
396396

397397
public_send(method_name, op)
398-
rescue Mongo::Error, BSON::String::IllegalKey, Mongo::Auth::Unauthorized, ArgumentError => e
398+
rescue Mongo::Error, bson_error, Mongo::Auth::Unauthorized, ArgumentError => e
399399
if expected_error.use('isClientError')
400400
# isClientError doesn't actually mean a client error.
401401
# It means anything other than OperationFailure. DRIVERS-1799
@@ -554,5 +554,14 @@ def create_client(**opts)
554554
).update(opts)
555555
Mongo::Client.new(*args)
556556
end
557+
558+
# The error to rescue BSON tests for. If we still define
559+
# BSON::String::IllegalKey then we should rescue that particular error,
560+
# otherwise, rescue an arbitrary BSON::Error
561+
def bson_error
562+
BSON::String.const_defined?(:IllegalKey) ?
563+
BSON::String.const_get(:IllegalKey) :
564+
BSON::Error
565+
end
557566
end
558567
end

spec/support/constraints.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,18 @@ def require_local_tls
1616
end
1717
end
1818
end
19+
20+
def max_bson_version(version)
21+
required_version = version.split('.').map(&:to_i)
22+
actual_version = bson_version(required_version.length)
23+
before(:all) do
24+
if (actual_version <=> required_version) > 0
25+
skip "bson-ruby version #{version} or lower is required"
26+
end
27+
end
28+
end
29+
30+
def bson_version(precision)
31+
BSON::VERSION.split('.')[0...precision].map(&:to_i)
32+
end
1933
end

0 commit comments

Comments
 (0)