|
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 |
| 11 | + |
| 12 | + let(:client) { authorized_client_without_any_retries } |
9 | 13 |
|
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 |
| 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 |
13 | 23 |
|
14 |
| - let(:client) { authorized_client_without_any_retries } |
| 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.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.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 | + expect(new_generation).to eq(generation + 1) |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + shared_examples_for 'does not clear connection pool' do |
| 56 | + it 'does not clear connection pool' do |
| 57 | + generation = server.pool.generation |
| 58 | + operation |
| 59 | + new_generation = server.pool.generation |
| 60 | + expect(new_generation).to eq(generation) |
| 61 | + end |
| 62 | + end |
| 63 | + |
| 64 | + describe 'when there is an error during an operation' do |
15 | 65 |
|
16 | 66 | before do
|
17 | 67 | wait_for_all_servers(client.cluster)
|
|
24 | 74 | end
|
25 | 75 | end
|
26 | 76 |
|
27 |
| - let(:server) { client.cluster.next_primary } |
28 |
| - |
29 | 77 | let(:operation) do
|
30 | 78 | expect_any_instance_of(Mongo::Server::Connection).to receive(:deliver).and_return(reply)
|
31 | 79 | expect do
|
32 | 80 | client.database.command(ping: 1)
|
33 | 81 | end.to raise_error(Mongo::Error::OperationFailure, exception_message)
|
34 | 82 | end
|
35 | 83 |
|
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 |
42 |
| - end |
43 |
| - |
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 |
50 |
| - end |
51 |
| - |
52 |
| - shared_examples_for 'requests server scan' do |
53 |
| - it 'requests server scan' do |
54 |
| - expect(server.scan_semaphore).to receive(:signal) |
55 |
| - operation |
56 |
| - end |
57 |
| - end |
58 |
| - |
59 |
| - shared_examples_for 'does not request server scan' do |
60 |
| - it 'does not request server scan' do |
61 |
| - expect(server.scan_semaphore).not_to receive(:signal) |
62 |
| - operation |
63 |
| - end |
64 |
| - end |
65 |
| - |
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) |
72 |
| - end |
73 |
| - end |
74 |
| - |
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 |
82 |
| - end |
83 |
| - |
84 | 84 | shared_examples_for 'not master or node recovering' do
|
85 | 85 | it_behaves_like 'marks server unknown'
|
86 | 86 | it_behaves_like 'requests server scan'
|
|
170 | 170 | end
|
171 | 171 | end
|
172 | 172 | end
|
| 173 | + |
| 174 | + # These tests fail intermittently in Evergreen |
| 175 | + describe 'when there is an error on monitoring connection', retry: 3 do |
| 176 | + let(:client) do |
| 177 | + authorized_client_without_any_retries.with( |
| 178 | + connect_timeout: 1, socket_timeout: 1) |
| 179 | + end |
| 180 | + |
| 181 | + let(:operation) do |
| 182 | + expect(server.monitor.connection).not_to be nil |
| 183 | + expect(server.monitor.connection).to receive(:ismaster).at_least(:once).and_raise(exception) |
| 184 | + server.scan_semaphore.broadcast |
| 185 | + 6.times do |
| 186 | + sleep 0.5 |
| 187 | + if server.unknown? |
| 188 | + break |
| 189 | + end |
| 190 | + end |
| 191 | + expect(server).to be_unknown |
| 192 | + end |
| 193 | + |
| 194 | + context 'non-timeout network error' do |
| 195 | + let(:exception) { Mongo::Error::SocketError } |
| 196 | + |
| 197 | + it_behaves_like 'marks server unknown' |
| 198 | + it_behaves_like 'clears connection pool' |
| 199 | + end |
| 200 | + |
| 201 | + context 'network timeout' do |
| 202 | + let(:exception) { Mongo::Error::SocketTimeoutError } |
| 203 | + |
| 204 | + it_behaves_like 'marks server unknown' |
| 205 | + it_behaves_like 'clears connection pool' |
| 206 | + end |
| 207 | + end |
173 | 208 | end
|
0 commit comments