@@ -108,7 +108,8 @@ var WriteConflictHelpers = (function() {
108108 // Make sure the collection is empty.
109109 assert . commandWorked ( coll . remove ( { } , { writeConcern : { w : "majority" } } ) ) ;
110110
111- const conn = coll . getDB ( ) . getMongo ( ) ;
111+ const testDB = coll . getDB ( ) ;
112+ const conn = testDB . getMongo ( ) ;
112113
113114 // Initiate two sessions.
114115 const sessionOptions = { causalConsistency : false } ;
@@ -120,7 +121,19 @@ var WriteConflictHelpers = (function() {
120121 tojson ( txn2Op ) ) ;
121122
122123 // Run the specified write conflict test.
123- writeConflictTestCase ( coll , session1 , session2 , txn1Op , txn2Op , initOp ) ;
124+ try {
125+ writeConflictTestCase ( coll , session1 , session2 , txn1Op , txn2Op , initOp ) ;
126+ } catch ( e ) {
127+ jsTestLog ( "Write conflict test case '" + writeConflictTestCase . name + "' failed." ) ;
128+ // We make sure to abort any idle transactions.
129+ let lsid1 = session1 . getSessionId ( ) ;
130+ let lsid2 = session2 . getSessionId ( ) ;
131+ print ( "Killing session with sessionID: " + tojson ( lsid1 ) ) ;
132+ assert . commandWorked ( testDB . runCommand ( { killSessions : [ lsid1 ] } ) ) ;
133+ print ( "Killing session with sessionID: " + tojson ( lsid2 ) ) ;
134+ assert . commandWorked ( testDB . runCommand ( { killSessions : [ lsid2 ] } ) ) ;
135+ throw e ;
136+ }
124137
125138 // Check the final state of the collection.
126139 assert . sameMembers ( expectedDocs , coll . find ( ) . toArray ( ) ) ;
0 commit comments