Sha256: 4d2360232259be1ba63fc156420771fd6ded0c3f08710d9a18f163b3fe281440

Contents?: true

Size: 1.63 KB

Versions: 26

Compression:

Stored size: 1.63 KB

Contents

require 'spec_helper'

describe Mongo::Protocol::Compressed do

  let(:original_message) { Mongo::Protocol::Query.new(SpecConfig.instance.test_db, TEST_COLL, { ping: 1 }) }
  let(:compressor) { 'zlib' }
  let(:level)      { nil }

  let(:message) do
    described_class.new(original_message, compressor, level)
  end

  describe '#serialize' do

    context 'when zlib compression level is not provided' do

      let(:original_message_bytes) do
        buf = BSON::ByteBuffer.new
        original_message.send(:serialize_fields, buf)
        buf.to_s
      end

      it 'does not set a compression level' do
        expect(Zlib::Deflate).to receive(:deflate).with(original_message_bytes, nil).and_call_original
        message.serialize
      end
    end

    context 'when zlib compression level is provided' do

      let(:level) { 1 }

      let(:original_message_bytes) do
        buf = BSON::ByteBuffer.new
        original_message.send(:serialize_fields, buf)
        buf.to_s
      end

      it 'uses the compression level' do
        expect(Zlib::Deflate).to receive(:deflate).with(original_message_bytes, 1).and_call_original
        message.serialize
      end
    end
  end

  describe '#replyable?' do

    context 'when the original message is replyable' do

      it 'returns true' do
        expect(message.replyable?).to be(true)
      end
    end

    context 'when the original message is not replyable' do
      min_server_fcv '3.6'

      let(:original_message) do
        Mongo::Protocol::Msg.new([:more_to_come], {}, { ping: 1 })
      end

      it 'returns false' do
        expect(message.replyable?).to be(false)
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/mongo-2.8.0/spec/mongo/protocol/compressed_spec.rb
mongo-2.11.6 spec/mongo/protocol/compressed_spec.rb
mongo-2.10.5 spec/mongo/protocol/compressed_spec.rb
mongo-2.11.5 spec/mongo/protocol/compressed_spec.rb
mongo-2.11.4 spec/mongo/protocol/compressed_spec.rb
mongo-2.10.4 spec/mongo/protocol/compressed_spec.rb
mongo-2.11.3 spec/mongo/protocol/compressed_spec.rb
mongo-2.11.2 spec/mongo/protocol/compressed_spec.rb
mongo-2.11.1 spec/mongo/protocol/compressed_spec.rb
mongo-2.10.3 spec/mongo/protocol/compressed_spec.rb
mongo-2.11.0 spec/mongo/protocol/compressed_spec.rb
mongo-2.9.2 spec/mongo/protocol/compressed_spec.rb
mongo-2.10.2 spec/mongo/protocol/compressed_spec.rb
mongo-2.11.0.rc0 spec/mongo/protocol/compressed_spec.rb
mongo-2.10.1 spec/mongo/protocol/compressed_spec.rb
mongo-2.10.0 spec/mongo/protocol/compressed_spec.rb
mongo-2.9.1 spec/mongo/protocol/compressed_spec.rb
mongo-2.10.0.rc0 spec/mongo/protocol/compressed_spec.rb
mongo-2.9.1.rc0 spec/mongo/protocol/compressed_spec.rb
mongo-2.9.0 spec/mongo/protocol/compressed_spec.rb