Skip to content

Commit a6d11fc

Browse files
committed
Bulk operations raise OperationFailure, not BulkWriteError, if write concern is invalid.
1 parent 1277fc9 commit a6d11fc

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

test/test_bulk.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -902,20 +902,27 @@ def test_fsync_and_j(self):
902902
OperationFailure,
903903
batch.execute, {'fsync': True, 'j': True})
904904

905+
def test_j_without_journal(self):
906+
client = self.coll.database.connection
907+
if not server_started_with_option(client, '--nojournal', 'nojournal'):
908+
raise SkipTest("Need mongod started with --nojournal")
909+
910+
# Using j=True without journaling is a hard failure.
911+
batch = self.coll.initialize_ordered_bulk_op()
912+
batch.insert({})
913+
self.assertRaises(OperationFailure, batch.execute, {'j': True})
914+
905915
def test_write_concern_failure_ordered(self):
906916

907917
batch = self.coll.initialize_ordered_bulk_op()
908918
batch.insert({'a': 1})
909919
batch.insert({'a': 2})
910920

911-
client = self.coll.database.connection
912-
# Using j=True without journaling is a hard failure.
913-
if server_started_with_option(client, '--nojournal', 'nojournal'):
914-
self.assertRaises(OperationFailure, batch.execute, {'j': True})
915-
# So is using w > 1 with no replication.
916-
elif not self.is_repl:
917-
self.assertRaises(BulkWriteError,
921+
# Using w > 1 with no replication is a hard failure.
922+
if not self.is_repl:
923+
self.assertRaises(OperationFailure,
918924
batch.execute, {'w': 5, 'wtimeout': 1})
925+
919926
# Replication wtimeout is a 'soft' error.
920927
# It shouldn't stop batch processing.
921928
else:

0 commit comments

Comments
 (0)