spec/integration/retryable_errors_spec.rb in mongo-2.12.4 vs spec/integration/retryable_errors_spec.rb in mongo-2.13.0.beta1
- old
+ new
@@ -2,12 +2,20 @@
describe 'Failing retryable operations' do
# Requirement for fail point
min_server_fcv '4.0'
+ let(:subscriber) { EventSubscriber.new }
+
+ let(:client_options) do
+ {}
+ end
+
let(:client) do
- subscribed_client
+ authorized_client.with(client_options).tap do |client|
+ client.subscribe(Mongo::Monitoring::COMMAND, subscriber)
+ end
end
let(:collection) do
client['retryable-errors-spec']
end
@@ -81,24 +89,33 @@
exception
end
let(:events) do
- EventSubscriber.command_started_events('find')
+ subscriber.command_started_events('find')
end
end
shared_context 'write operation' do
let(:fail_point_command) do
- {
+ command = {
configureFailPoint: 'failCommand',
mode: {times: 2},
data: {
failCommands: ['insert'],
errorCode: 11600,
},
}
+
+ if ClusterConfig.instance.short_server_version >= '4.3'
+ # Server versions 4.4 and newer will add the RetryableWriteError
+ # label to all retryable errors, and the driver must not add the label
+ # if it is not already present.
+ command[:data][:errorLabels] = ['RetryableWriteError']
+ end
+
+ command
end
let(:set_fail_point) do
client.use(:admin).database.command(fail_point_command)
end
@@ -117,11 +134,11 @@
exception
end
let(:events) do
- EventSubscriber.command_started_events('insert')
+ subscriber.command_started_events('insert')
end
end
shared_examples_for 'failing retry' do
@@ -130,10 +147,11 @@
expect(operation_exception.message).not_to include('attempt 1')
expect(operation_exception.message).not_to include('attempt 3')
end
it 'publishes two events' do
+ operation_exception
expect(events.length).to eq(2)
end
end
@@ -144,10 +162,11 @@
expect(operation_exception.message).not_to include('attempt 2')
expect(operation_exception.message).not_to include('attempt 3')
end
it 'publishes one event' do
+ operation_exception
expect(events.length).to eq(1)
end
end
@@ -206,31 +225,31 @@
include_context 'read operation'
context 'modern read retries' do
require_wired_tiger_on_36
- let(:client) do
- subscribed_client.with(retry_reads: true)
+ let(:client_options) do
+ {retry_reads: true}
end
it_behaves_like 'failing retry'
it_behaves_like 'modern retry'
end
context 'legacy read retries' do
- let(:client) do
- subscribed_client.with(retry_reads: false, read_retry_interval: 0)
+ let(:client_options) do
+ {retry_reads: false, read_retry_interval: 0}
end
it_behaves_like 'failing retry'
it_behaves_like 'legacy retry'
end
end
context 'when read retries are disabled' do
- let(:client) do
- subscribed_client.with(retry_reads: false, max_read_retries: 0)
+ let(:client_options) do
+ {retry_reads: false, max_read_retries: 0}
end
include_context 'read operation'
it_behaves_like 'failing single attempt'
@@ -241,20 +260,20 @@
include_context 'write operation'
context 'modern write retries' do
require_wired_tiger_on_36
- let(:client) do
- subscribed_client.with(retry_writes: true)
+ let(:client_options) do
+ {retry_writes: true}
end
it_behaves_like 'failing retry'
it_behaves_like 'modern retry'
end
context 'legacy write' do
- let(:client) do
- subscribed_client.with(retry_writes: false)
+ let(:client_options) do
+ {retry_writes: false}
end
it_behaves_like 'failing retry'
it_behaves_like 'legacy retry'
end