Sha256: 61446bc5ac186695a7ad6e5dd974cec6b6425225dd7b308dc7bef50f68bc5617

Contents?: true

Size: 1.75 KB

Versions: 11

Compression:

Stored size: 1.75 KB

Contents

require 'spec_helper'

def ignore?(test)
  if version = test.ignore_if_server_version_greater_than
    return true if version == "3.0" && find_command_enabled?
  end
  if version = test.ignore_if_server_version_less_than
    return true if version == "3.1" && !find_command_enabled?
  end
  false
end

describe 'Command Monitoring Events' do

  COMMAND_MONITORING_TESTS.each do |file|


    spec = Mongo::CommandMonitoring::Spec.new(file)

    spec.tests.each do |test|

      context(test.description) do

        let(:subscriber) do
          Mongo::CommandMonitoring::TestSubscriber.new
        end

        let(:monitoring) do
          authorized_client.send(:monitoring)
        end

        before do
          authorized_collection.find.delete_many
          authorized_client.subscribe(Mongo::Monitoring::COMMAND, subscriber)
        end

        after do
          monitoring.subscribers[Mongo::Monitoring::COMMAND].delete(subscriber)
          authorized_collection.find.delete_many
        end

        test.expectations.each do |expectation|

          before do
            if ignore?(test)
              skip 'Preconditions not met'
            end
          end

          it "generates a #{expectation.event_name} for #{expectation.command_name}" do
            begin
              test.run(authorized_collection)
              event = subscriber.send(expectation.event_type)[expectation.command_name]
              expect(event).to send(expectation.matcher, expectation)
            rescue Mongo::Error::OperationFailure, Mongo::Error::BulkWriteError
              event = subscriber.send(expectation.event_type)[expectation.command_name]
              expect(event).to send(expectation.matcher, expectation)
            end
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/mongo-2.8.0/spec/spec_tests/command_monitoring_spec.rb
mongo-2.8.0 spec/spec_tests/command_monitoring_spec.rb
mongo-2.7.2 spec/spec_tests/command_monitoring_spec.rb
mongo-2.8.0.rc0 spec/spec_tests/command_monitoring_spec.rb
mongo-2.7.1 spec/spec_tests/command_monitoring_spec.rb
mongo-2.7.0 spec/spec_tests/command_monitoring_spec.rb
mongo-2.7.0.rc0 spec/spec_tests/command_monitoring_spec.rb
mongo-2.6.4 spec/spec_tests/command_monitoring_spec.rb
mongo-2.6.2 spec/spec_tests/command_monitoring_spec.rb
mongo-2.6.1 spec/spec_tests/command_monitoring_spec.rb
mongo-2.6.0 spec/spec_tests/command_monitoring_spec.rb