Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 1 addition & 43 deletions test/asynchronous/test_retryable_writes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2017 MongoDB, Inc.
# Copyright 2017-present MongoDB, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,7 +43,6 @@
from bson.int64 import Int64
from bson.raw_bson import RawBSONDocument
from bson.son import SON
from pymongo.asynchronous.mongo_client import AsyncMongoClient
from pymongo.errors import (
AutoReconnect,
ConnectionFailure,
Expand Down Expand Up @@ -226,47 +225,6 @@ async def test_supported_single_statement_no_retry(self):
f"{msg} sent txnNumber with {event.command_name}",
)

@async_client_context.require_no_standalone
async def test_supported_single_statement_supported_cluster(self):
for method, args, kwargs in retryable_single_statement_ops(self.db.retryable_write_test):
msg = f"{method.__name__}(*{args!r}, **{kwargs!r})"
self.listener.reset()
await method(*args, **kwargs)
commands_started = self.listener.started_events
self.assertEqual(len(self.listener.succeeded_events), 1, msg)
first_attempt = commands_started[0]
self.assertIn(
"lsid",
first_attempt.command,
f"{msg} sent no lsid with {first_attempt.command_name}",
)
initial_session_id = first_attempt.command["lsid"]
self.assertIn(
"txnNumber",
first_attempt.command,
f"{msg} sent no txnNumber with {first_attempt.command_name}",
)

# There should be no retry when the failpoint is not active.
if async_client_context.is_mongos or not async_client_context.test_commands_enabled:
self.assertEqual(len(commands_started), 1)
continue

initial_transaction_id = first_attempt.command["txnNumber"]
retry_attempt = commands_started[1]
self.assertIn(
"lsid",
retry_attempt.command,
f"{msg} sent no lsid with {first_attempt.command_name}",
)
self.assertEqual(retry_attempt.command["lsid"], initial_session_id, msg)
self.assertIn(
"txnNumber",
retry_attempt.command,
f"{msg} sent no txnNumber with {first_attempt.command_name}",
)
self.assertEqual(retry_attempt.command["txnNumber"], initial_transaction_id, msg)

async def test_supported_single_statement_unsupported_cluster(self):
if async_client_context.is_rs or async_client_context.is_mongos:
raise SkipTest("This cluster supports retryable writes")
Expand Down
144 changes: 144 additions & 0 deletions test/retryable_writes/unified/aggregate-out-merge.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{
"description": "aggregate with $out/$merge does not set txnNumber",
"schemaVersion": "1.3",
"runOnRequirements": [
{
"minServerVersion": "3.6",
"topologies": [
"replicaset",
"sharded",
"load-balanced"
]
}
],
"createEntities": [
{
"client": {
"id": "client0",
"observeEvents": [
"commandStartedEvent"
]
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "retryable-writes-tests"
}
},
{
"collection": {
"id": "collection0",
"database": "database0",
"collectionName": "coll0"
}
}
],
"initialData": [
{
"collectionName": "mergeCollection",
"databaseName": "retryable-writes-tests",
"documents": []
}
],
"tests": [
{
"description": "aggregate with $out does not set txnNumber",
"operations": [
{
"object": "collection0",
"name": "aggregate",
"arguments": {
"pipeline": [
{
"$sort": {
"x": 1
}
},
{
"$match": {
"_id": {
"$gt": 1
}
}
},
{
"$out": "outCollection"
}
]
}
}
],
"expectEvents": [
{
"client": "client0",
"events": [
{
"commandStartedEvent": {
"commandName": "aggregate",
"command": {
"txnNumber": {
"$$exists": false
}
}
}
}
]
}
]
},
{
"description": "aggregate with $merge does not set txnNumber",
"runOnRequirements": [
{
"minServerVersion": "4.1.11"
}
],
"operations": [
{
"object": "collection0",
"name": "aggregate",
"arguments": {
"pipeline": [
{
"$sort": {
"x": 1
}
},
{
"$match": {
"_id": {
"$gt": 1
}
}
},
{
"$merge": {
"into": "mergeCollection"
}
}
]
}
}
],
"expectEvents": [
{
"client": "client0",
"events": [
{
"commandStartedEvent": {
"commandName": "aggregate",
"command": {
"txnNumber": {
"$$exists": false
}
}
}
}
]
}
]
}
]
}
154 changes: 153 additions & 1 deletion test/retryable_writes/unified/bulkWrite.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
{
"client": {
"id": "client0",
"useMultipleMongoses": false
"useMultipleMongoses": false,
"observeEvents": [
"commandStartedEvent"
]
}
},
{
Expand Down Expand Up @@ -121,6 +124,53 @@
}
]
}
],
"expectEvents": [
{
"client": "client0",
"events": [
{
"commandStartedEvent": {
"commandName": "insert",
"command": {
"txnNumber": {
"$$exists": true
}
}
}
},
{
"commandStartedEvent": {
"commandName": "insert",
"command": {
"txnNumber": {
"$$exists": true
}
}
}
},
{
"commandStartedEvent": {
"commandName": "update",
"command": {
"txnNumber": {
"$$exists": true
}
}
}
},
{
"commandStartedEvent": {
"commandName": "delete",
"command": {
"txnNumber": {
"$$exists": true
}
}
}
}
]
}
]
},
{
Expand Down Expand Up @@ -510,6 +560,33 @@
}
]
}
],
"expectEvents": [
{
"client": "client0",
"events": [
{
"commandStartedEvent": {
"commandName": "insert",
"command": {
"txnNumber": {
"$$exists": true
}
}
}
},
{
"commandStartedEvent": {
"commandName": "insert",
"command": {
"txnNumber": {
"$$exists": true
}
}
}
}
]
}
]
},
{
Expand Down Expand Up @@ -926,6 +1003,81 @@
]
}
]
},
{
"description": "collection bulkWrite with updateMany does not set txnNumber",
"operations": [
{
"object": "collection0",
"name": "bulkWrite",
"arguments": {
"requests": [
{
"updateMany": {
"filter": {},
"update": {
"$set": {
"x": 1
}
}
}
}
]
}
}
],
"expectEvents": [
{
"client": "client0",
"events": [
{
"commandStartedEvent": {
"commandName": "update",
"command": {
"txnNumber": {
"$$exists": false
}
}
}
}
]
}
]
},
{
"description": "collection bulkWrite with deleteMany does not set txnNumber",
"operations": [
{
"object": "collection0",
"name": "bulkWrite",
"arguments": {
"requests": [
{
"deleteMany": {
"filter": {}
}
}
]
}
}
],
"expectEvents": [
{
"client": "client0",
"events": [
{
"commandStartedEvent": {
"commandName": "delete",
"command": {
"txnNumber": {
"$$exists": false
}
}
}
}
]
}
]
}
]
}
Loading
Loading