File: server_monitor_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 (57 lines) | stat: -rw-r--r-- 1,423 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
45
46
47
48
49
50
51
52
53
54
55
56
57
# frozen_string_literal: true
# rubocop:todo all

require 'spec_helper'

describe 'Server::Monitor' do
  require_topology :single, :replica_set, :sharded

  let(:client) do
    new_local_client([ClusterConfig.instance.primary_address_str],
      SpecConfig.instance.test_options.merge(SpecConfig.instance.auth_options.merge(
        monitor_options)))
  end

  let(:monitor_options) do
    {heartbeat_frequency: 1}
  end

  retry_test
  it 'refreshes server descriptions in background' do
    server = client.cluster.next_primary

    expect(server.description).not_to be_unknown

    server.unknown!

    # This is racy, especially in JRuby, because the monitor may have
    # already run and updated the description. Because of this we retry
    # the test a few times.
    expect(server.description).to be_unknown

    # Wait for background thread to update the description
    sleep 1.5

    expect(server.description).not_to be_unknown
  end

  context 'server-pushed hello' do
    min_server_fcv '4.4'
    require_topology :replica_set

    let(:monitor_options) do
      {heartbeat_frequency: 20}
    end

    it 'updates server description' do
      starting_primary_address = client.cluster.next_primary.address

      ClusterTools.instance.step_down

      sleep 2

      new_primary_address = client.cluster.next_primary.address
      new_primary_address.should_not == starting_primary_address
    end
  end
end