|
5 | 5 | ClientRegistry.instance.close_all_clients
|
6 | 6 | end
|
7 | 7 |
|
8 |
| - describe 'when there is an error during an operation' do |
| 8 | + # These tests operate on specific servers, and don't work in a multi |
| 9 | + # shard cluster where multiple servers are equally eligible |
| 10 | + require_no_multi_shard |
9 | 11 |
|
10 |
| - # These tests operate on specific servers, and don't work in a multi |
11 |
| - # shard cluster where multiple servers are equally eligible |
12 |
| - require_no_multi_shard |
| 12 | + let(:client) { authorized_client_without_any_retries } |
13 | 13 |
|
14 |
| - let(:client) { authorized_client_without_any_retries } |
| 14 | + let(:server) { client.cluster.next_primary } |
15 | 15 |
|
16 |
| - before do |
17 |
| - wait_for_all_servers(client.cluster) |
18 |
| - # we also need a connection to the primary so that our error |
19 |
| - # expectations do not get triggered during handshakes which |
20 |
| - # have different behavior from non-handshake errors |
21 |
| - client.database.command(ping: 1) |
22 |
| - client.cluster.servers_list.each do |server| |
23 |
| - server.monitor.stop!(true) |
24 |
| - end |
| 16 | + shared_examples_for 'marks server unknown' do |
| 17 | + it 'marks server unknown' do |
| 18 | + expect(server).not_to be_unknown |
| 19 | + operation |
| 20 | + expect(server).to be_unknown |
25 | 21 | end
|
| 22 | + end |
26 | 23 |
|
27 |
| - let(:server) { client.cluster.next_primary } |
28 |
| - |
29 |
| - let(:operation) do |
30 |
| - expect_any_instance_of(Mongo::Server::Connection).to receive(:deliver).and_return(reply) |
31 |
| - expect do |
32 |
| - client.database.command(ping: 1) |
33 |
| - end.to raise_error(Mongo::Error::OperationFailure, exception_message) |
| 24 | + shared_examples_for 'does not mark server unknown' do |
| 25 | + it 'does not mark server unknown' do |
| 26 | + expect(server).not_to be_unknown |
| 27 | + operation |
| 28 | + expect(server).not_to be_unknown |
34 | 29 | end
|
| 30 | + end |
35 | 31 |
|
36 |
| - shared_examples_for 'marks server unknown' do |
37 |
| - it 'marks server unknown' do |
38 |
| - expect(server).not_to be_unknown |
39 |
| - operation |
40 |
| - expect(server).to be_unknown |
41 |
| - end |
| 32 | + shared_examples_for 'requests server scan' do |
| 33 | + it 'requests server scan' do |
| 34 | + expect(server.monitor.scan_semaphore).to receive(:signal) |
| 35 | + operation |
42 | 36 | end
|
| 37 | + end |
43 | 38 |
|
44 |
| - shared_examples_for 'does not mark server unknown' do |
45 |
| - it 'does not mark server unknown' do |
46 |
| - expect(server).not_to be_unknown |
47 |
| - operation |
48 |
| - expect(server).not_to be_unknown |
49 |
| - end |
| 39 | + shared_examples_for 'does not request server scan' do |
| 40 | + it 'does not request server scan' do |
| 41 | + expect(server.monitor.scan_semaphore).not_to receive(:signal) |
| 42 | + operation |
50 | 43 | end
|
| 44 | + end |
51 | 45 |
|
52 |
| - shared_examples_for 'requests server scan' do |
53 |
| - it 'requests server scan' do |
54 |
| - expect(server.monitor.scan_semaphore).to receive(:signal) |
55 |
| - operation |
56 |
| - end |
| 46 | + shared_examples_for 'clears connection pool' do |
| 47 | + it 'clears connection pool' do |
| 48 | + generation = server.pool.generation |
| 49 | + operation |
| 50 | + new_generation = server.pool.generation |
| 51 | + # Temporary hack to allow repeated pool clears |
| 52 | + expect(new_generation).to be >= generation + 1 |
57 | 53 | end
|
| 54 | + end |
58 | 55 |
|
59 |
| - shared_examples_for 'does not request server scan' do |
60 |
| - it 'does not request server scan' do |
61 |
| - expect(server.monitor.scan_semaphore).not_to receive(:signal) |
62 |
| - operation |
63 |
| - end |
| 56 | + shared_examples_for 'does not clear connection pool' do |
| 57 | + it 'does not clear connection pool' do |
| 58 | + generation = server.pool.generation |
| 59 | + operation |
| 60 | + new_generation = server.pool.generation |
| 61 | + expect(new_generation).to eq(generation) |
64 | 62 | end
|
| 63 | + end |
| 64 | + |
| 65 | + describe 'when there is an error during an operation' do |
65 | 66 |
|
66 |
| - shared_examples_for 'clears connection pool' do |
67 |
| - it 'clears connection pool' do |
68 |
| - generation = server.pool.generation |
69 |
| - operation |
70 |
| - new_generation = server.pool.generation |
71 |
| - expect(new_generation).to eq(generation + 1) |
| 67 | + before do |
| 68 | + wait_for_all_servers(client.cluster) |
| 69 | + # we also need a connection to the primary so that our error |
| 70 | + # expectations do not get triggered during handshakes which |
| 71 | + # have different behavior from non-handshake errors |
| 72 | + client.database.command(ping: 1) |
| 73 | + client.cluster.servers_list.each do |server| |
| 74 | + server.monitor.stop! |
72 | 75 | end
|
73 | 76 | end
|
74 | 77 |
|
75 |
| - shared_examples_for 'does not clear connection pool' do |
76 |
| - it 'does not clear connection pool' do |
77 |
| - generation = server.pool.generation |
78 |
| - operation |
79 |
| - new_generation = server.pool.generation |
80 |
| - expect(new_generation).to eq(generation) |
81 |
| - end |
| 78 | + let(:operation) do |
| 79 | + expect_any_instance_of(Mongo::Server::Connection).to receive(:deliver).and_return(reply) |
| 80 | + expect do |
| 81 | + client.database.command(ping: 1) |
| 82 | + end.to raise_error(Mongo::Error::OperationFailure, exception_message) |
82 | 83 | end
|
83 | 84 |
|
84 | 85 | shared_examples_for 'not master or node recovering' do
|
|
88 | 89 | context 'server 4.2 or higher' do
|
89 | 90 | min_server_fcv '4.2'
|
90 | 91 |
|
91 |
| - it_behaves_like 'does not clear connection pool' |
| 92 | + # Due to RUBY-1894 backport, the pool is cleared here |
| 93 | + it_behaves_like 'clears connection pool' |
92 | 94 | end
|
93 | 95 |
|
94 | 96 | context 'server 4.0 or lower' do
|
|
170 | 172 | end
|
171 | 173 | end
|
172 | 174 | end
|
| 175 | + |
| 176 | + # These tests fail intermittently in Evergreen |
| 177 | + describe 'when there is an error on monitoring connection', retry: 3 do |
| 178 | + let(:client) do |
| 179 | + authorized_client_without_any_retries.with( |
| 180 | + connect_timeout: 1, socket_timeout: 1) |
| 181 | + end |
| 182 | + |
| 183 | + let(:operation) do |
| 184 | + expect(server.monitor.connection).not_to be nil |
| 185 | + expect(server.monitor.connection).to receive(:ismaster).at_least(:once).and_raise(exception) |
| 186 | + server.monitor.scan_semaphore.broadcast |
| 187 | + 6.times do |
| 188 | + sleep 0.5 |
| 189 | + if server.unknown? |
| 190 | + break |
| 191 | + end |
| 192 | + end |
| 193 | + expect(server).to be_unknown |
| 194 | + end |
| 195 | + |
| 196 | + context 'non-timeout network error' do |
| 197 | + let(:exception) { Mongo::Error::SocketError } |
| 198 | + |
| 199 | + it_behaves_like 'marks server unknown' |
| 200 | + it_behaves_like 'clears connection pool' |
| 201 | + end |
| 202 | + |
| 203 | + context 'network timeout' do |
| 204 | + let(:exception) { Mongo::Error::SocketTimeoutError } |
| 205 | + |
| 206 | + it_behaves_like 'marks server unknown' |
| 207 | + it_behaves_like 'clears connection pool' |
| 208 | + end |
| 209 | + end |
173 | 210 | end
|
0 commit comments