@@ -26,6 +26,17 @@ class SessionTransactionSpecError < StandardError; end
2626 collection . delete_many
2727 end
2828
29+ describe 'start_transaction' do
30+ context 'when topology is sharded and server is < 4.2' do
31+ max_server_fcv '4.1'
32+ require_topology :sharded
33+
34+ it 'raises an error' do
35+ expect { session . start_transaction } . to raise_error ( Mongo ::Error ::TransactionsNotSupported , /sharded transactions require server version/ )
36+ end
37+ end
38+ end
39+
2940 describe '#abort_transaction' do
3041 require_topology :replica_set
3142
@@ -75,6 +86,8 @@ class SessionTransactionSpecError < StandardError; end
7586 end
7687
7788 describe '#with_transaction' do
89+ require_topology :replica_set
90+
7891 context 'callback successful' do
7992 it 'commits' do
8093 session . with_transaction do
@@ -123,6 +136,7 @@ class SessionTransactionSpecError < StandardError; end
123136 expect ( Mongo ::Utils ) . to receive ( :monotonic_time ) . ordered . and_return ( start + 1 )
124137 expect ( Mongo ::Utils ) . to receive ( :monotonic_time ) . ordered . and_return ( start + 2 )
125138 expect ( Mongo ::Utils ) . to receive ( :monotonic_time ) . ordered . and_return ( start + 200 )
139+ allow ( session ) . to receive ( 'check_transactions_supported!' ) . and_return true
126140
127141 expect do
128142 session . with_transaction do
@@ -156,6 +170,7 @@ class SessionTransactionSpecError < StandardError; end
156170 expect ( Mongo ::Utils ) . to receive ( :monotonic_time ) . ordered . and_return ( start + i )
157171 end
158172 expect ( Mongo ::Utils ) . to receive ( :monotonic_time ) . ordered . and_return ( start + 200 )
173+ allow ( session ) . to receive ( 'check_transactions_supported!' ) . and_return true
159174
160175 exc = Mongo ::Error ::OperationFailure . new ( 'timeout test' )
161176 exc . add_label ( label )
0 commit comments