Sha256: 6b209cb62a6adccda9fb7cef1823846f8acdc68e9c5ee50cdf55345ac290019e

Contents?: true

Size: 1.45 KB

Versions: 9

Compression:

Stored size: 1.45 KB

Contents

require 'spec_helper'

describe 'Cleanup stress test' do
  require_stress

  let(:options) do
    SpecConfig.instance.all_test_options
  end

  before(:all) do
    # load if necessary
    ClusterConfig.instance.primary_address
    ClientRegistry.instance.close_all_clients
  end

  context 'single client disconnect/reconnect' do
    let(:client) do
      new_local_client([ClusterConfig.instance.primary_address.seed], options)
    end

    it 'cleans up' do
      client
      client.cluster.servers_list.map(&:scan!)

      sleep 1
      GC.start

      start_resources = resources

      500.times do
        client.close
        client.reconnect
      end

      sleep 1
      GC.start

      end_resources = resources

      # There seem to be a temporary file descriptor leak in CI,
      # where we start with 75 fds and end with 77 fds.
      # Allow a few to be leaked, run more iterations to ensure the leak
      # is not a real one.
      # Sometimes we end with fewer fds than we started with also...
      end_resources[:open_file_count].should >= start_resources[:open_file_count] - 3
      end_resources[:open_file_count].should <= start_resources[:open_file_count] + 3

      end_resources[:running_thread_count].should == start_resources[:running_thread_count]
    end
  end

  def resources
    {
      open_file_count: Dir["/proc/#{Process.pid}/fd/*"].count,
      running_thread_count: Thread.list.select { |thread| thread.status == 'run' }.count,
    }
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mongo-2.13.3 spec/stress/cleanup_spec.rb
mongo-2.14.1 spec/stress/cleanup_spec.rb
mongo-2.15.0.alpha spec/stress/cleanup_spec.rb
mongo-2.13.2 spec/stress/cleanup_spec.rb
mongo-2.14.0 spec/stress/cleanup_spec.rb
mongo-2.14.0.rc1 spec/stress/cleanup_spec.rb
mongo-2.13.1 spec/stress/cleanup_spec.rb
mongo-2.13.0 spec/stress/cleanup_spec.rb
mongo-2.13.0.rc1 spec/stress/cleanup_spec.rb