File: push_monitor_close_spec.rb

package info (click to toggle)
ruby-mongo 2.21.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 14,764 kB
  • sloc: ruby: 108,806; makefile: 5; sh: 2
file content (44 lines) | stat: -rw-r--r-- 1,192 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# frozen_string_literal: true
# rubocop:todo all

require 'spec_helper'

# This test repeatedly creates and closes clients across several threads.
# Its goal is to ensure that the push monitor connections specifically get
# closed without any errors or warnings being reported to applications.
#
# Although the test is specifically meant to test 4.4+ servers (that utilize
# the push monitor) in non-LB connections, run it everywhere for good measure.
describe 'Push monitor close 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

  it 'does not warn/error on cleanup' do
    Mongo::Logger.logger.should_not receive(:warn)

    threads = 10.times.map do
      Thread.new do
        10.times do
          client = new_local_client([ClusterConfig.instance.primary_address.seed], options)
          if rand > 0.33
            client.command(ping: 1)
            sleep(rand * 3)
          end
          client.close
          STDOUT << '.'
        end
      end
    end
    threads.each(&:join)
    puts
  end
end