Skip to content

Commit a761c45

Browse files
p-mongop
andcommitted
RUBY-2447 Fix intermittent transaction examples test failures (#2135)
* run tx examples first * add diagnostics to transaction aborts * try majority read/write concerns * flush router config to work around SERVER-53015 Co-authored-by: Oleg Pudeyev <oleg@bsdpower.com>
1 parent b2f5b15 commit a761c45

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

Rakefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ CLASSIFIERS = [
3232
[%r,^spec_tests,, :spec],
3333
]
3434

35-
RUN_PRIORITY = %i(unit
35+
RUN_PRIORITY = %i(
3636
tx_examples
37+
unit
3738
integration sdam_integration cursor_reaping query_cache
3839
spec spec_sdam_integration
3940
)

lib/mongo/session.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ def with_transaction(options=nil)
379379
rv = yield self
380380
rescue Exception => e
381381
if within_states?(STARTING_TRANSACTION_STATE, TRANSACTION_IN_PROGRESS_STATE)
382+
log_warn("Aborting transaction due to #{e.class}: #{e}")
382383
abort_transaction
383384
transaction_in_progress = false
384385
end
@@ -443,7 +444,7 @@ def with_transaction(options=nil)
443444
true
444445
ensure
445446
if transaction_in_progress
446-
log_warn('with_transaction callback altered with_transaction loop, aborting transaction')
447+
log_warn('with_transaction callback broke out of with_transaction loop, aborting transaction')
447448
begin
448449
abort_transaction
449450
rescue Error::OperationFailure, Error::InvalidTransactionOperation

spec/integration/transactions_examples_spec.rb

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,42 @@
44
require_wired_tiger
55
require_transaction_support
66

7+
let(:client) do
8+
authorized_client.with(read_concern: {level: :majority}, write: {w: :majority})
9+
end
10+
711
let(:hr) do
8-
authorized_client.use(:hr).database
12+
client.use(:hr).database
913
end
1014

1115
let(:reporting) do
12-
authorized_client.use(:reporting).database
16+
client.use(:reporting).database
1317
end
1418

1519
before(:each) do
1620
hr[:employees].insert_one(employee: 3, status: 'Active')
21+
22+
# Sanity check since this test likes to fail
23+
employee = hr[:employees].find({ employee: 3 }, limit: 1).first
24+
expect(employee).to_not be_nil
25+
1726
reporting[:events].insert_one(employee: 3, status: { new: 'Active', old: nil})
1827
end
1928

2029
after(:each) do
2130
hr.drop
2231
reporting.drop
32+
33+
# Work around https://jira.mongodb.org/browse/SERVER-53015
34+
::Utils.mongos_each_direct_client do |client|
35+
client.database.command(flushRouterConfig: 1)
36+
end
2337
end
2438

2539
context 'individual examples' do
2640

2741
let(:session) do
28-
authorized_client.start_session
42+
client.start_session
2943
end
3044

3145
# Start Transactions Intro Example 1
@@ -142,10 +156,6 @@ def commit_with_retry(session)
142156

143157
context 'Transactions Retry Example 3 (combined example)' do
144158

145-
let(:client) do
146-
authorized_client
147-
end
148-
149159
let(:run_transaction) do
150160

151161
# Start Transactions Retry Example 3

0 commit comments

Comments
 (0)