Sha256: 81cf0a8d5e6ee34b98d7b0ce78d7d0ad76ec355e1667c6e9351249a11807c8bb

Contents?: true

Size: 1.5 KB

Versions: 18

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

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

18 entries across 18 versions & 1 rubygems

Version Path
mongo-2.16.4 spec/stress/cleanup_spec.rb
mongo-2.17.4 spec/stress/cleanup_spec.rb
mongo-2.18.3 spec/stress/cleanup_spec.rb
mongo-2.18.2 spec/stress/cleanup_spec.rb
mongo-2.17.3 spec/stress/cleanup_spec.rb
mongo-2.18.1 spec/stress/cleanup_spec.rb
mongo-2.18.0 spec/stress/cleanup_spec.rb
mongo-2.17.2 spec/stress/cleanup_spec.rb
mongo-2.16.3 spec/stress/cleanup_spec.rb
mongo-2.18.0.beta1 spec/stress/cleanup_spec.rb
mongo-2.16.2 spec/stress/cleanup_spec.rb
mongo-2.17.1 spec/stress/cleanup_spec.rb
mongo-2.16.1 spec/stress/cleanup_spec.rb
mongo-2.17.0 spec/stress/cleanup_spec.rb
mongo-2.16.0 spec/stress/cleanup_spec.rb
mongo-2.15.1 spec/stress/cleanup_spec.rb
mongo-2.16.0.alpha1 spec/stress/cleanup_spec.rb
mongo-2.15.0 spec/stress/cleanup_spec.rb