|
5 | 5 | ClientRegistry.instance.close_all_clients
|
6 | 6 | end
|
7 | 7 |
|
| 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_topology :replica_set |
| 11 | + |
| 12 | + let(:client) { authorized_client_without_any_retries } |
| 13 | + |
| 14 | + let(:server) { client.cluster.next_primary } |
| 15 | + |
| 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 |
| 21 | + end |
| 22 | + end |
| 23 | + |
| 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 |
| 29 | + end |
| 30 | + end |
| 31 | + |
| 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 |
| 36 | + end |
| 37 | + end |
| 38 | + |
| 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 |
| 43 | + end |
| 44 | + end |
| 45 | + |
| 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 |
| 53 | + end |
| 54 | + end |
| 55 | + |
| 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) |
| 62 | + end |
| 63 | + end |
| 64 | + |
8 | 65 | describe 'when there is an error during an operation' do
|
9 |
| - let(:client) { authorized_client_without_any_retries } |
10 | 66 |
|
11 | 67 | before do
|
12 | 68 | wait_for_all_servers(client.cluster)
|
|
15 | 71 | # have different behavior from non-handshake errors
|
16 | 72 | client.database.command(ping: 1)
|
17 | 73 | client.cluster.servers_list.each do |server|
|
18 |
| - server.monitor.stop!(true) |
| 74 | + server.monitor.stop! |
19 | 75 | end
|
20 | 76 | end
|
21 | 77 |
|
22 |
| - let(:server) { client.cluster.next_primary } |
23 |
| - |
24 | 78 | let(:operation) do
|
25 | 79 | expect_any_instance_of(Mongo::Server::Connection).to receive(:deliver).and_return(reply)
|
26 | 80 | expect do
|
27 | 81 | client.database.command(ping: 1)
|
28 | 82 | end.to raise_error(Mongo::Error::OperationFailure, exception_message)
|
29 | 83 | end
|
30 | 84 |
|
31 |
| - shared_examples_for 'marks server unknown' do |
32 |
| - it 'marks server unknown' do |
33 |
| - expect(server).not_to be_unknown |
34 |
| - operation |
35 |
| - expect(server).to be_unknown |
36 |
| - end |
37 |
| - end |
38 |
| - |
39 |
| - shared_examples_for 'does not mark server unknown' do |
40 |
| - it 'does not mark server unknown' do |
41 |
| - expect(server).not_to be_unknown |
42 |
| - operation |
43 |
| - expect(server).not_to be_unknown |
44 |
| - end |
45 |
| - end |
46 |
| - |
47 |
| - shared_examples_for 'requests server scan' do |
48 |
| - it 'requests server scan' do |
49 |
| - expect(server.monitor.scan_semaphore).to receive(:signal) |
50 |
| - operation |
51 |
| - end |
52 |
| - end |
53 |
| - |
54 |
| - shared_examples_for 'does not request server scan' do |
55 |
| - it 'does not request server scan' do |
56 |
| - expect(server.monitor.scan_semaphore).not_to receive(:signal) |
57 |
| - operation |
58 |
| - end |
59 |
| - end |
60 |
| - |
61 |
| - shared_examples_for 'clears connection pool' do |
62 |
| - it 'clears connection pool' do |
63 |
| - generation = server.pool.generation |
64 |
| - operation |
65 |
| - new_generation = server.pool.generation |
66 |
| - expect(new_generation).to eq(generation + 1) |
67 |
| - end |
68 |
| - end |
69 |
| - |
70 |
| - shared_examples_for 'does not clear connection pool' do |
71 |
| - it 'does not clear connection pool' do |
72 |
| - generation = server.pool.generation |
73 |
| - operation |
74 |
| - new_generation = server.pool.generation |
75 |
| - expect(new_generation).to eq(generation) |
76 |
| - end |
77 |
| - end |
78 |
| - |
79 | 85 | shared_examples_for 'not master or node recovering' do
|
80 | 86 | it_behaves_like 'marks server unknown'
|
81 | 87 | it_behaves_like 'requests server scan'
|
82 | 88 |
|
83 | 89 | context 'server 4.2 or higher' do
|
84 | 90 | min_server_fcv '4.2'
|
85 | 91 |
|
86 |
| - 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' |
87 | 94 | end
|
88 | 95 |
|
89 | 96 | context 'server 4.0 or lower' do
|
|
165 | 172 | end
|
166 | 173 | end
|
167 | 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 |
168 | 210 | end
|
0 commit comments