diff --git a/lib/mongo/operation/map_reduce/result.rb b/lib/mongo/operation/map_reduce/result.rb index 9a1c251336..d14c0d82f8 100644 --- a/lib/mongo/operation/map_reduce/result.rb +++ b/lib/mongo/operation/map_reduce/result.rb @@ -80,7 +80,7 @@ def documents # @since 2.0.0 # @api public def successful? - !documents.nil? + !documents.nil? && parser.message.empty? end # Get the execution time of the map/reduce. @@ -112,7 +112,11 @@ def time # @since 2.0.0 # @api private def validate! - documents.nil? ? raise_operation_failure : self + if documents.nil? || !parser.message.empty? + raise_operation_failure + else + self + end end # Get the cursor id. diff --git a/spec/mongo/operation/map_reduce/result_spec.rb b/spec/mongo/operation/map_reduce/result_spec.rb new file mode 100644 index 0000000000..0d7047d1a6 --- /dev/null +++ b/spec/mongo/operation/map_reduce/result_spec.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Mongo::Operation::MapReduce::Result do + let(:description) do + Mongo::Server::Description.new( + double('description address'), + { 'minWireVersion' => 0, 'maxWireVersion' => 2 } + ) + end + + let(:result) do + described_class.new(reply, description) + end + + let(:reply) do + Mongo::Protocol::Reply.new.tap do |reply| + reply.instance_variable_set(:@flags, []) + reply.instance_variable_set(:@cursor_id, 0) + reply.instance_variable_set(:@starting_from, 0) + reply.instance_variable_set(:@number_returned, documents.size) + reply.instance_variable_set(:@documents, documents) + end + end + + let(:aggregate) do + [ { '_id' => 'Berlin', 'population' => 3_000_000 } ] + end + + describe '#successful?' do + context 'when the reply has no errors' do + let(:documents) do + [ { 'results' => aggregate, 'ok' => 1.0 } ] + end + + it 'returns true' do + expect(result).to be_successful + end + end + + context 'when the reply has a write concern error' do + let(:documents) do + [ + { + 'results' => aggregate, + 'ok' => 1.0, + 'writeConcernError' => { + 'code' => 64, + 'errmsg' => 'waiting replication timed out' + } + } + ] + end + + it 'returns false' do + expect(result).not_to be_successful + end + end + end +end diff --git a/spec/runners/unified/crud_operations.rb b/spec/runners/unified/crud_operations.rb index 2314948ee8..b9b9571b69 100644 --- a/spec/runners/unified/crud_operations.rb +++ b/spec/runners/unified/crud_operations.rb @@ -325,6 +325,16 @@ def aggregate(op) obj.aggregate(pipeline, **opts).to_a end + def map_reduce(op) + obj = entities.get_any(op.use!('object')) + args = op.use!('arguments') + map = args.use!('map') + reduce = args.use!('reduce') + out = args.use!('out') + + Mongo::Collection::View.new(obj).map_reduce(map, reduce, out: out).to_a + end + def create_find_cursor(op) obj = entities.get_any(op.use!('object')) args = op.use!('arguments') diff --git a/spec/runners/unified/grid_fs_operations.rb b/spec/runners/unified/grid_fs_operations.rb index e587c0517a..addfdd101a 100644 --- a/spec/runners/unified/grid_fs_operations.rb +++ b/spec/runners/unified/grid_fs_operations.rb @@ -26,6 +26,16 @@ def delete(op) end end + def delete_by_name(op) + bucket = entities.get(:bucket, op.use!('object')) + use_arguments(op) do |args| + filename = args.use!('filename') + bucket.find(filename: filename).to_a.each do |file| + bucket.delete(file['_id']) + end + end + end + def download(op) bucket = entities.get(:bucket, op.use!('object')) use_arguments(op) do |args| diff --git a/spec/spec_tests/data/read_write_concern/write_concern_errors/aggregate.yml b/spec/spec_tests/data/read_write_concern/write_concern_errors/aggregate.yml new file mode 100644 index 0000000000..86a9f04198 --- /dev/null +++ b/spec/spec_tests/data/read_write_concern/write_concern_errors/aggregate.yml @@ -0,0 +1,66 @@ +description: write-concern-errors-aggregate + +schemaVersion: "1.0" + +createEntities: + - client: + id: &client0 client0 + useMultipleMongoses: false + - database: + id: &database0 database0 + client: *client0 + databaseName: &database_name write-concern-errors-tests + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: &collection_name coll + +# Create the database used for aggregate to avoid a NamespaceNotFound error. +initialData: + - collectionName: *collection_name + databaseName: *database_name + documents: [] + +tests: + - description: aggregate with $out reports a writeConcernError + operations: + - name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [ aggregate ] + writeConcernError: &write_concern_error + code: 79 + codeName: UnknownReplWriteConcern + - name: aggregate + object: *collection0 + arguments: + pipeline: + - $match: { _id: { $gt: 1 } } + - $out: "aggregate_out" + expectError: &expect_write_concern_error + errorCode: 79 + + - description: aggregate with $merge reports a writeConcernError + operations: + - name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [ aggregate ] + writeConcernError: *write_concern_error + - name: aggregate + object: *collection0 + arguments: + pipeline: + - $match: { _id: { $gt: 1 } } + - $merge: { into: "aggregate_merge" } + expectError: *expect_write_concern_error diff --git a/spec/spec_tests/data/read_write_concern/write_concern_errors/bulkWrite.yml b/spec/spec_tests/data/read_write_concern/write_concern_errors/bulkWrite.yml new file mode 100644 index 0000000000..04b4bc0b83 --- /dev/null +++ b/spec/spec_tests/data/read_write_concern/write_concern_errors/bulkWrite.yml @@ -0,0 +1,40 @@ +description: write-concern-errors-bulkWrite + +schemaVersion: "1.0" + +createEntities: + - client: + id: &client0 client0 + useMultipleMongoses: false + - database: + id: &database0 database0 + client: *client0 + databaseName: write-concern-errors-tests + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: coll + +tests: + - description: bulkWrite reports a writeConcernError + operations: + - name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [ insert ] + writeConcernError: + code: 79 + codeName: UnknownReplWriteConcern + - name: bulkWrite + object: *collection0 + arguments: + requests: + - insertOne: + document: { x: 33 } + expectError: + isError: true diff --git a/spec/spec_tests/data/read_write_concern/write_concern_errors/client-bulkWrite.yml b/spec/spec_tests/data/read_write_concern/write_concern_errors/client-bulkWrite.yml new file mode 100644 index 0000000000..63be5d62f3 --- /dev/null +++ b/spec/spec_tests/data/read_write_concern/write_concern_errors/client-bulkWrite.yml @@ -0,0 +1,37 @@ +description: write-concern-errors-client-bulkWrite + +schemaVersion: "1.21" + +runOnRequirements: + - minServerVersion: "8.0" + +createEntities: + - client: + id: &client0 client0 + useMultipleMongoses: false + +tests: + - description: clientBulkWrite reports a writeConcernError + operations: + - name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [ bulkWrite ] + writeConcernError: + code: 79 + codeName: UnknownReplWriteConcern + - name: clientBulkWrite + object: *client0 + arguments: + models: + - insertOne: + namespace: write-concern-errors-tests.coll + document: { x: 33 } + expectError: + writeConcernErrors: + - code: 79 diff --git a/spec/spec_tests/data/read_write_concern/write_concern_errors/client-side-encryption.yml b/spec/spec_tests/data/read_write_concern/write_concern_errors/client-side-encryption.yml new file mode 100644 index 0000000000..f43c864fdc --- /dev/null +++ b/spec/spec_tests/data/read_write_concern/write_concern_errors/client-side-encryption.yml @@ -0,0 +1,129 @@ +description: write-concern-errors-client-side-encryption + +schemaVersion: "1.8" + +runOnRequirements: + - csfle: true + +createEntities: + - client: + id: &client0 client0 + useMultipleMongoses: false + - clientEncryption: + id: &clientEncryption0 clientEncryption0 + clientEncryptionOpts: + keyVaultClient: *client0 + keyVaultNamespace: keyvault.datakeys + kmsProviders: + local: { key: { $$placeholder: 1 } } + +initialData: + - databaseName: keyvault + collectionName: datakeys + documents: + - _id: { $binary: { base64: bG9jYWxrZXlsb2NhbGtleQ==, subType: "04" } } + keyAltNames: ["local_key"] + keyMaterial: + { + $binary: + { + base64: ABKBldDEoDW323yejOnIRk6YQmlD9d3eQthd16scKL75nz2LjNL9fgPDZWrFFOlqlhMCFaSrNJfGrFUjYk5JFDO7soG5Syb50k1niJoKg4ilsj0L4mpimFUtTpOr2nzZOeQtvAksEXc7gsFgq8gV7t/U3lsaXPY7I0t42DfSE8EGlPdxRjFdHnxh+OR8h7U9b8Qs5K5UuhgyeyxaBZ1Hgw==, + subType: "00", + }, + } + creationDate: { $date: { $numberLong: "1641024000000" } } + updateDate: { $date: { $numberLong: "1641024000000" } } + status: 1 + masterKey: + provider: local + +tests: + - description: rewrapManyDataKey reports a writeConcernError + operations: + - name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [ update ] + writeConcernError: &write_concern_error + code: 79 + codeName: UnknownReplWriteConcern + - name: rewrapManyDataKey + object: *clientEncryption0 + arguments: + filter: {} + opts: + provider: local + expectError: + isError: true + + - description: createDataKey reports a writeConcernError + operations: + - name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [ insert ] + writeConcernError: *write_concern_error + - name: createDataKey + object: *clientEncryption0 + arguments: + kmsProvider: local + expectError: &expect_write_concern_error + errorCode: 79 + + - description: deleteKey reports a writeConcernError + operations: + - name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [ delete ] + writeConcernError: *write_concern_error + - name: deleteKey + object: *clientEncryption0 + arguments: + id: &local_key_id { $binary: { base64: bG9jYWxrZXlsb2NhbGtleQ==, subType: "04" } } + expectError: *expect_write_concern_error + + - description: addKeyAltName reports a writeConcernError + operations: + - &failPoint_findAndModify + name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [ findAndModify ] + writeConcernError: *write_concern_error + - name: addKeyAltName + object: *clientEncryption0 + arguments: + id: *local_key_id + keyAltName: new_key_alt_name + expectError: *expect_write_concern_error + + - description: removeKeyAltName reports a writeConcernError + operations: + - *failPoint_findAndModify + - name: removeKeyAltName + object: *clientEncryption0 + arguments: + id: *local_key_id + keyAltName: local_key + expectError: *expect_write_concern_error diff --git a/spec/spec_tests/data/read_write_concern/write_concern_errors/crud.yml b/spec/spec_tests/data/read_write_concern/write_concern_errors/crud.yml new file mode 100644 index 0000000000..947fa2c93d --- /dev/null +++ b/spec/spec_tests/data/read_write_concern/write_concern_errors/crud.yml @@ -0,0 +1,119 @@ +description: write-concern-errors-crud + +schemaVersion: "1.0" + +createEntities: + - client: + id: &client0 client0 + useMultipleMongoses: false + - database: + id: &database0 database0 + client: *client0 + databaseName: write-concern-errors-tests + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: coll + +tests: + - description: insertOne reports a writeConcernError + operations: + - &failPoint_insert + name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [ insert ] + writeConcernError: &write_concern_error + code: 79 + codeName: UnknownReplWriteConcern + - name: insertOne + object: *collection0 + arguments: + document: { x: 33 } + expectError: &expect_write_concern_error + errorCode: 79 + + - description: insertMany reports a writeConcernError + operations: + - *failPoint_insert + - name: insertMany + object: *collection0 + arguments: + documents: + - { x: 44 } + - { x: 55 } + expectError: + isError: true + + - description: updateOne reports a writeConcernError + operations: + - &failPoint_update + name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [ update ] + writeConcernError: *write_concern_error + - name: updateOne + object: *collection0 + arguments: + filter: { _id: 1 } + update: { $set: { x: 111 } } + expectError: *expect_write_concern_error + + - description: updateMany reports a writeConcernError + operations: + - *failPoint_update + - name: updateMany + object: *collection0 + arguments: + filter: {} + update: { $inc: { x: 1 } } + expectError: *expect_write_concern_error + + - description: replaceOne reports a writeConcernError + operations: + - *failPoint_update + - name: replaceOne + object: *collection0 + arguments: + filter: { _id: 2 } + replacement: { x: 222 } + expectError: *expect_write_concern_error + + - description: deleteOne reports a writeConcernError + operations: + - &failPoint_delete + name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [ delete ] + writeConcernError: *write_concern_error + - name: deleteOne + object: *collection0 + arguments: + filter: { _id: 1 } + expectError: *expect_write_concern_error + + - description: deleteMany reports a writeConcernError + operations: + - *failPoint_delete + - name: deleteMany + object: *collection0 + arguments: + filter: {} + expectError: *expect_write_concern_error diff --git a/spec/spec_tests/data/read_write_concern/write_concern_errors/db-coll-management.yml b/spec/spec_tests/data/read_write_concern/write_concern_errors/db-coll-management.yml new file mode 100644 index 0000000000..0b8e8f2e5e --- /dev/null +++ b/spec/spec_tests/data/read_write_concern/write_concern_errors/db-coll-management.yml @@ -0,0 +1,106 @@ +description: write-concern-errors-db-coll-management + +schemaVersion: "1.0" + +createEntities: + - client: + id: &client0 client0 + useMultipleMongoses: false + - database: + id: &database0 database0 + client: *client0 + databaseName: &database_name write-concern-errors-tests + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: &collection_name coll + +# Create the collection to be renamed to avoid a NamespaceNotFound error. +initialData: + - collectionName: *collection_name + databaseName: *database_name + documents: [] + +tests: + - description: createCollection reports a writeConcernError + operations: + - name: dropCollection + object: *database0 + arguments: + collection: &created_collection coll_create + - name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [ create ] + writeConcernError: &write_concern_error + code: 79 + codeName: UnknownReplWriteConcern + - name: createCollection + object: *database0 + arguments: + collection: *created_collection + expectError: &expect_write_concern_error + errorCode: 79 + + - description: dropCollection reports a writeConcernError + operations: + - name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [ drop ] + writeConcernError: *write_concern_error + - name: dropCollection + object: *database0 + arguments: + collection: *collection_name + expectError: *expect_write_concern_error + + - description: rename reports a writeConcernError + operations: + - name: dropCollection + object: *database0 + arguments: + collection: &renamed_collection coll_renamed + - name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [ renameCollection ] + writeConcernError: *write_concern_error + - name: rename + object: *collection0 + arguments: + to: *renamed_collection + expectError: *expect_write_concern_error + + - description: dropDatabase reports a writeConcernError + operations: + - name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [ dropDatabase ] + writeConcernError: *write_concern_error + - name: dropDatabase + object: *client0 + arguments: + database: write-concern-errors-dropdb + expectError: *expect_write_concern_error diff --git a/spec/spec_tests/data/read_write_concern/write_concern_errors/findAndModify.yml b/spec/spec_tests/data/read_write_concern/write_concern_errors/findAndModify.yml new file mode 100644 index 0000000000..c9f0924baa --- /dev/null +++ b/spec/spec_tests/data/read_write_concern/write_concern_errors/findAndModify.yml @@ -0,0 +1,59 @@ +description: write-concern-errors-findAndModify + +schemaVersion: "1.0" + +createEntities: + - client: + id: &client0 client0 + useMultipleMongoses: false + - database: + id: &database0 database0 + client: *client0 + databaseName: write-concern-errors-tests + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: coll + +tests: + - description: findOneAndUpdate reports a writeConcernError + operations: + - &failPoint_findAndModify + name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [ findAndModify ] + writeConcernError: + code: 79 + codeName: UnknownReplWriteConcern + - name: findOneAndUpdate + object: *collection0 + arguments: + filter: { _id: 1 } + update: { $set: { x: 111 } } + expectError: &expect_write_concern_error + errorCode: 79 + + - description: findOneAndReplace reports a writeConcernError + operations: + - *failPoint_findAndModify + - name: findOneAndReplace + object: *collection0 + arguments: + filter: { _id: 2 } + replacement: { x: 222 } + expectError: *expect_write_concern_error + + - description: findOneAndDelete reports a writeConcernError + operations: + - *failPoint_findAndModify + - name: findOneAndDelete + object: *collection0 + arguments: + filter: { _id: 1 } + expectError: *expect_write_concern_error diff --git a/spec/spec_tests/data/read_write_concern/write_concern_errors/gridfs.yml b/spec/spec_tests/data/read_write_concern/write_concern_errors/gridfs.yml new file mode 100644 index 0000000000..5603f0954b --- /dev/null +++ b/spec/spec_tests/data/read_write_concern/write_concern_errors/gridfs.yml @@ -0,0 +1,144 @@ +description: write-concern-errors-gridfs + +schemaVersion: "1.0" + +createEntities: + - client: + id: &client0 client0 + useMultipleMongoses: false + - database: + id: &database0 database0 + client: *client0 + databaseName: &database_name write-concern-errors-tests + - bucket: + id: &bucket0 bucket0 + database: *database0 + +initialData: + - databaseName: *database_name + collectionName: fs.files + documents: + - _id: &file_id { $oid: "000000000000000000000001" } + length: 0 + chunkSize: 4 + uploadDate: { $date: "1970-01-01T00:00:00.000Z" } + filename: filename + - databaseName: *database_name + collectionName: fs.chunks + documents: [] + +tests: + - description: upload reports a writeConcernError from a chunk insert + operations: + - name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [ insert ] + writeConcernError: &write_concern_error + code: 79 + codeName: UnknownReplWriteConcern + - name: upload + object: *bucket0 + arguments: + filename: filename + source: { $$hexBytes: "1122334455" } + expectError: &expect_write_concern_error + errorCode: 79 + + - description: upload reports a writeConcernError from the files document insert + operations: + - name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { skip: 1 } + data: + failCommands: [ insert ] + writeConcernError: *write_concern_error + - name: upload + object: *bucket0 + arguments: + filename: filename + source: { $$hexBytes: "1122334455" } + expectError: *expect_write_concern_error + + - description: delete reports a writeConcernError + operations: + - name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [ delete ] + writeConcernError: *write_concern_error + - name: delete + object: *bucket0 + arguments: + id: *file_id + expectError: *expect_write_concern_error + + - description: deleteByName reports a writeConcernError + operations: + - name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [ delete ] + writeConcernError: *write_concern_error + - name: deleteByName + object: *bucket0 + arguments: + filename: filename + expectError: *expect_write_concern_error + + - description: file rename reports a writeConcernError + operations: + - name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [ update ] + writeConcernError: *write_concern_error + - name: rename + object: *bucket0 + arguments: + id: *file_id + newFilename: newfilename + expectError: *expect_write_concern_error + + - description: renameByName reports a writeConcernError + operations: + - name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [ update ] + writeConcernError: *write_concern_error + - name: renameByName + object: *bucket0 + arguments: + filename: filename + newFilename: newfilename + expectError: *expect_write_concern_error diff --git a/spec/spec_tests/data/read_write_concern/write_concern_errors/index-management.yml b/spec/spec_tests/data/read_write_concern/write_concern_errors/index-management.yml new file mode 100644 index 0000000000..aa1e7d457e --- /dev/null +++ b/spec/spec_tests/data/read_write_concern/write_concern_errors/index-management.yml @@ -0,0 +1,74 @@ +description: write-concern-errors-index-management + +schemaVersion: "1.0" + +createEntities: + - client: + id: &client0 client0 + useMultipleMongoses: false + - database: + id: &database0 database0 + client: *client0 + databaseName: write-concern-errors-tests + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: coll + +tests: + - description: createIndex reports a writeConcernError + operations: + - name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [ createIndexes ] + writeConcernError: &write_concern_error + code: 79 + codeName: UnknownReplWriteConcern + - name: createIndex + object: *collection0 + arguments: + keys: { x: 1 } + expectError: &expect_write_concern_error + errorCode: 79 + + - description: dropIndex reports a writeConcernError + operations: + - name: createIndex + object: *collection0 + arguments: + keys: { x: 1 } + name: x_1 + - &failPoint_dropIndexes + name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [ dropIndexes ] + writeConcernError: *write_concern_error + - name: dropIndex + object: *collection0 + arguments: + name: x_1 + expectError: *expect_write_concern_error + + - description: dropIndexes reports a writeConcernError + operations: + - name: createIndex + object: *collection0 + arguments: + keys: { x: 1 } + name: x_1 + - *failPoint_dropIndexes + - name: dropIndexes + object: *collection0 + expectError: *expect_write_concern_error diff --git a/spec/spec_tests/data/read_write_concern/write_concern_errors/mapReduce.yml b/spec/spec_tests/data/read_write_concern/write_concern_errors/mapReduce.yml new file mode 100644 index 0000000000..649a2cf03d --- /dev/null +++ b/spec/spec_tests/data/read_write_concern/write_concern_errors/mapReduce.yml @@ -0,0 +1,48 @@ +description: write-concern-errors-mapReduce + +schemaVersion: "1.0" + +createEntities: + - client: + id: &client0 client0 + useMultipleMongoses: false + - database: + id: &database0 database0 + client: *client0 + databaseName: &database_name write-concern-errors-tests + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: &collection_name coll + +# Create the database used for mapReduce to avoid a NamespaceNotFound error. +initialData: + - collectionName: *collection_name + databaseName: *database_name + documents: + - { _id: 1, x: 11 } + - { _id: 2, x: 22 } + +tests: + - description: mapReduce with an output collection reports a writeConcernError + operations: + - name: failPoint + object: testRunner + arguments: + client: *client0 + failPoint: + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [ mapReduce ] + writeConcernError: + code: 79 + codeName: UnknownReplWriteConcern + - name: mapReduce + object: *collection0 + arguments: + map: { $code: "function inc() { return emit(0, this.x + 1) }" } + reduce: { $code: "function sum(key, values) { return values.reduce((acc, x) => acc + x); }" } + out: { replace: "mapreduce_out" } + expectError: + errorCode: 79 diff --git a/spec/spec_tests/read_write_concern_unified_spec.rb b/spec/spec_tests/read_write_concern_unified_spec.rb new file mode 100644 index 0000000000..828637127b --- /dev/null +++ b/spec/spec_tests/read_write_concern_unified_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require 'runners/unified' + +base = "#{CURRENT_PATH}/spec_tests/data/read_write_concern/write_concern_errors" +RW_CONCERN_WCE_TESTS = Dir.glob("#{base}/**/*.yml").sort + +describe 'Read write concern write concern error unified spec tests' do + define_unified_spec_tests( + base, + RW_CONCERN_WCE_TESTS, + skip_descriptions: { + # The Ruby driver does not implement GridFS file rename, so the + # rename operations cannot be exercised. + 'file rename reports a writeConcernError' => 'Ruby driver does not support GridFS rename', + 'renameByName reports a writeConcernError' => 'Ruby driver does not support GridFS rename', + } + ) +end