Skip to content

Commit 1ecac82

Browse files
authored
Use errorContains: E11000 in all spec tests formerly referencing DuplicateKey (#1522)
* Use errorContains: E11000 in all spec tests formerly referencing DuplicateKey * Guard against shards being empty * Fix multiple mongos requirement to only apply in sharded topologies
1 parent 3e70216 commit 1ecac82

File tree

5 files changed

+13
-10
lines changed

5 files changed

+13
-10
lines changed

spec/spec_tests/data/transactions/abort.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,10 @@ tests:
305305
document:
306306
_id: 1
307307
result:
308-
# Don't assert on errorCodeName because (after SERVER-38583) the
309-
# DuplicateKey is reported in writeErrors, not as a top-level
310-
# command error.
311308
errorLabelsOmit: ["TransientTransactionError", "UnknownTransactionCommitResult"]
309+
# DuplicateKey error code included in the bulk write error message
310+
# returned by the server
311+
errorContains: E11000
312312
# Make sure the server aborted the transaction.
313313
- name: insertOne
314314
object: collection

spec/spec_tests/data/transactions/error-labels.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ tests:
2525
- _id: 1
2626
- _id: 1
2727
result:
28-
# Don't assert on errorCodeName because (after SERVER-38583) the
29-
# DuplicateKey is reported in writeErrors, not as a top-level
30-
# command error.
3128
errorLabelsOmit: ["TransientTransactionError", "UnknownTransactionCommitResult"]
29+
# DuplicateKey error code included in the bulk write error message
30+
# returned by the server
31+
errorContains: E11000
3232
- name: abortTransaction
3333
object: session0
3434

spec/spec_tests/data/transactions_api/callback-retry.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ tests:
160160
result:
161161
errorLabelsOmit: ["TransientTransactionError", "UnknownTransactionCommitResult"]
162162
result:
163-
# Don't assert on errorCodeName because (after SERVER-38583) the
164-
# DuplicateKey is reported in writeErrors, not as a top-level
165-
# command error.
166163
errorLabelsOmit: ["TransientTransactionError", "UnknownTransactionCommitResult"]
164+
# DuplicateKey error code included in the bulk write error message
165+
# returned by the server
166+
errorContains: E11000
167167
expectations:
168168
-
169169
command_started_event:

spec/support/cluster_config.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ def storage_engine
9595
client = ClientRegistry.instance.global_client('root_authorized')
9696
if topology == :sharded
9797
shards = client.use(:admin).command(listShards: 1).first
98+
if shards['shards'].empty?
99+
raise 'Shards are empty'
100+
end
98101
shard = shards['shards'].first
99102
address_str = shard['host'].sub(/^.*\//, '').sub(/,.*/, '')
100103
client = ClusterTools.instance.direct_client(address_str,

spec/support/transactions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def define_transactions_spec_tests(test_paths)
3131

3232
before do
3333
if test.multiple_mongoses?
34-
unless SpecConfig.instance.addresses.length > 1
34+
if ClusterConfig.instance.topology == :sharded && SpecConfig.instance.addresses.length == 1
3535
skip "Test requires multiple mongoses"
3636
end
3737
else

0 commit comments

Comments
 (0)