@@ -19,63 +19,82 @@ These tests use a cursor's address field to track which server an operation was
19
19
driver, use command monitoring instead.
20
20
21
21
1 . Test that starting a new transaction on a pinned ClientSession unpins the session and normal server selection is
22
- performed for the next operation.
23
-
24
- ``` python
25
- @require_server_version (4 , 1 , 6 )
26
- @require_mongos_count_at_least (2 )
27
- def test_unpin_for_next_transaction (self ):
28
- # Increase localThresholdMS and wait until both nodes are discovered
29
- # to avoid false positives.
30
- client = MongoClient(mongos_hosts, localThresholdMS = 1000 )
31
- wait_until(lambda : len (client.nodes) > 1 )
32
- # Create the collection.
33
- client.test.test.insert_one({})
34
- with client.start_session() as s:
35
- # Session is pinned to Mongos.
36
- with s.start_transaction():
37
- client.test.test.insert_one({}, session = s)
38
-
39
- addresses = set ()
40
- for _ in range (50 ):
41
- with s.start_transaction():
42
- cursor = client.test.test.find({}, session = s)
43
- assert next (cursor)
44
- addresses.add(cursor.address)
45
-
46
- assert len (addresses) > 1
47
- ```
22
+ performed for the next operation.
23
+
24
+ ``` python
25
+ @require_server_version (4 , 1 , 6 )
26
+ @require_mongos_count_at_least (2 )
27
+ def test_unpin_for_next_transaction (self ):
28
+ # Increase localThresholdMS and wait until both nodes are discovered
29
+ # to avoid false positives.
30
+ client = MongoClient(mongos_hosts, localThresholdMS = 1000 )
31
+ wait_until(lambda : len (client.nodes) > 1 )
32
+ # Create the collection.
33
+ client.test.test.insert_one({})
34
+ with client.start_session() as s:
35
+ # Session is pinned to Mongos.
36
+ with s.start_transaction():
37
+ client.test.test.insert_one({}, session = s)
38
+
39
+ addresses = set ()
40
+ for _ in range (50 ):
41
+ with s.start_transaction():
42
+ cursor = client.test.test.find({}, session = s)
43
+ assert next (cursor)
44
+ addresses.add(cursor.address)
45
+
46
+ assert len (addresses) > 1
47
+ ```
48
48
49
49
2 . Test non- transaction operations using a pinned ClientSession unpins the session and normal server selection is
50
- performed.
51
-
52
- ``` python
53
- @require_server_version (4 , 1 , 6 )
54
- @require_mongos_count_at_least (2 )
55
- def test_unpin_for_non_transaction_operation (self ):
56
- # Increase localThresholdMS and wait until both nodes are discovered
57
- # to avoid false positives.
58
- client = MongoClient(mongos_hosts, localThresholdMS = 1000 )
59
- wait_until(lambda : len (client.nodes) > 1 )
60
- # Create the collection.
61
- client.test.test.insert_one({})
62
- with client.start_session() as s:
63
- # Session is pinned to Mongos.
64
- with s.start_transaction():
65
- client.test.test.insert_one({}, session = s)
66
-
67
- addresses = set ()
68
- for _ in range (50 ):
69
- cursor = client.test.test.find({}, session = s)
70
- assert next (cursor)
71
- addresses.add(cursor.address)
72
-
73
- assert len (addresses) > 1
74
- ```
50
+ performed.
51
+
52
+ ```python
53
+ @require_server_version (4 , 1 , 6 )
54
+ @require_mongos_count_at_least (2 )
55
+ def test_unpin_for_non_transaction_operation (self ):
56
+ # Increase localThresholdMS and wait until both nodes are discovered
57
+ # to avoid false positives.
58
+ client = MongoClient(mongos_hosts, localThresholdMS = 1000 )
59
+ wait_until(lambda : len (client.nodes) > 1 )
60
+ # Create the collection.
61
+ client.test.test.insert_one({})
62
+ with client.start_session() as s:
63
+ # Session is pinned to Mongos.
64
+ with s.start_transaction():
65
+ client.test.test.insert_one({}, session = s)
66
+
67
+ addresses = set ()
68
+ for _ in range (50 ):
69
+ cursor = client.test.test.find({}, session = s)
70
+ assert next (cursor)
71
+ addresses.add(cursor.address)
72
+
73
+ assert len (addresses) > 1
74
+ ```
75
+
76
+ 3 . Test that `PoolClearedError` has `TransientTransactionError` label. Since there is no simple way to trigger
77
+ `PoolClearedError` , this test should be implemented in a way that suites each driver the best.
78
+
79
+ # # Options Inside Transaction Prose Tests.
80
+
81
+ These prose tests ensure drivers handle options inside a transaction where the unified tests do not suffice. Ensure
82
+ these tests do not run against a standalone server.
83
+
84
+ # ## 1.0 Write concern not inherited from collection object inside transaction.
85
+
86
+ - Create a MongoClient running against a configured sharded/ replica set / load balanced cluster.
87
+ - Start a new session on the client.
88
+ - Start a transaction on the session.
89
+ - Instantiate a collection object in the driver with a default write concern of `{ w: 0 }` .
90
+ - Insert the document `{ n: 1 }` on the instantiated collection.
91
+ - Commit the transaction.
92
+ - End the session.
93
+ - Ensure the document was inserted and no error was thrown from the transaction.
75
94
76
95
# # Changelog
77
96
97
+ - 2024 - 10 - 31 : Add test for PoolClearedError.
78
98
- 2024 - 02 - 15 : Migrated from reStructuredText to Markdown.
79
- - 2024-02-07: Converted legacy transaction tests to unified format and moved the\
80
- legacy test format docs to a separate
81
- file.
99
+ - 2024 - 02 - 07 : Converted legacy transaction tests to unified format and moved the legacy test format docs to a separate
100
+ file .
0 commit comments