|
61 | 61 | end |
62 | 62 | end |
63 | 63 |
|
| 64 | + # rubocop:disable Naming/VariableName, RSpec/InstanceVariable |
64 | 65 | describe 'Connection Pool Backpressure' do |
65 | 66 | min_server_fcv '8.2' |
66 | 67 | require_topology :single |
|
72 | 73 | SpecConfig.instance.addresses, |
73 | 74 | SpecConfig.instance.all_test_options.merge( |
74 | 75 | max_connecting: 100, |
75 | | - max_pool_size: 100, |
76 | | - ), |
| 76 | + max_pool_size: 100 |
| 77 | + ) |
77 | 78 | ).tap do |client| |
78 | 79 | client.subscribe(Mongo::Monitoring::CONNECTION_POOL, subscriber) |
79 | 80 | end |
|
89 | 90 | defined?(@prev_ingressConnectionEstablishmentMaxQueueDepth) |
90 | 91 | admin_db.command( |
91 | 92 | setParameter: 1, |
92 | | - ingressConnectionEstablishmentRateLimiterEnabled: @prev_ingressConnectionEstablishmentRateLimiterEnabled, |
| 93 | + ingressConnectionEstablishmentRateLimiterEnabled: @prev_ingressConnectionEstablishmentRateLimiterEnabled |
93 | 94 | ) |
94 | 95 | admin_db.command( |
95 | 96 | setParameter: 1, |
96 | | - ingressConnectionEstablishmentRatePerSec: @prev_ingressConnectionEstablishmentRatePerSec, |
| 97 | + ingressConnectionEstablishmentRatePerSec: @prev_ingressConnectionEstablishmentRatePerSec |
97 | 98 | ) |
98 | 99 | admin_db.command( |
99 | 100 | setParameter: 1, |
100 | | - ingressConnectionEstablishmentBurstCapacitySecs: @prev_ingressConnectionEstablishmentBurstCapacitySecs, |
| 101 | + ingressConnectionEstablishmentBurstCapacitySecs: @prev_ingressConnectionEstablishmentBurstCapacitySecs |
101 | 102 | ) |
102 | 103 | admin_db.command( |
103 | 104 | setParameter: 1, |
104 | | - ingressConnectionEstablishmentMaxQueueDepth: @prev_ingressConnectionEstablishmentMaxQueueDepth, |
| 105 | + ingressConnectionEstablishmentMaxQueueDepth: @prev_ingressConnectionEstablishmentMaxQueueDepth |
105 | 106 | ) |
106 | 107 | else |
107 | 108 | # Fallback: at least disable the limiter if previous values were not captured. |
108 | 109 | admin_db.command( |
109 | 110 | setParameter: 1, |
110 | | - ingressConnectionEstablishmentRateLimiterEnabled: false, |
| 111 | + ingressConnectionEstablishmentRateLimiterEnabled: false |
111 | 112 | ) |
112 | 113 | end |
113 | 114 | end |
|
121 | 122 | ingressConnectionEstablishmentRateLimiterEnabled: 1, |
122 | 123 | ingressConnectionEstablishmentRatePerSec: 1, |
123 | 124 | ingressConnectionEstablishmentBurstCapacitySecs: 1, |
124 | | - ingressConnectionEstablishmentMaxQueueDepth: 1, |
| 125 | + ingressConnectionEstablishmentMaxQueueDepth: 1 |
125 | 126 | ).first |
126 | 127 |
|
127 | 128 | @prev_ingressConnectionEstablishmentRateLimiterEnabled = |
|
136 | 137 | # Enable the ingress rate limiter with test-specific values. |
137 | 138 | admin_db.command( |
138 | 139 | setParameter: 1, |
139 | | - ingressConnectionEstablishmentRateLimiterEnabled: true, |
| 140 | + ingressConnectionEstablishmentRateLimiterEnabled: true |
140 | 141 | ) |
141 | 142 | admin_db.command( |
142 | 143 | setParameter: 1, |
143 | | - ingressConnectionEstablishmentRatePerSec: 20, |
| 144 | + ingressConnectionEstablishmentRatePerSec: 20 |
144 | 145 | ) |
145 | 146 | admin_db.command( |
146 | 147 | setParameter: 1, |
147 | | - ingressConnectionEstablishmentBurstCapacitySecs: 1, |
| 148 | + ingressConnectionEstablishmentBurstCapacitySecs: 1 |
148 | 149 | ) |
149 | 150 | admin_db.command( |
150 | 151 | setParameter: 1, |
151 | | - ingressConnectionEstablishmentMaxQueueDepth: 1, |
| 152 | + ingressConnectionEstablishmentMaxQueueDepth: 1 |
152 | 153 | ) |
153 | 154 |
|
154 | 155 | # Add a document so $where has something to process. |
155 | 156 | client.use('test')['test'].delete_many |
156 | 157 | client.use('test')['test'].insert_one({}) |
157 | 158 |
|
158 | 159 | # Run 100 parallel find_one operations that contend for connections. |
159 | | - threads = 100.times.map do |
| 160 | + threads = Array.new(100) do |
160 | 161 | Thread.new do |
161 | | - begin |
162 | | - client.use('test')['test'].find( |
163 | | - '$where' => 'function() { sleep(2000); return true; }' |
164 | | - ).first |
165 | | - rescue StandardError |
166 | | - # Ignore connection errors (including checkout timeouts). |
167 | | - end |
| 162 | + client.use('test')['test'].find( |
| 163 | + '$where' => 'function() { sleep(2000); return true; }' |
| 164 | + ).first |
| 165 | + rescue StandardError |
| 166 | + # Ignore connection errors (including checkout timeouts). |
168 | 167 | end |
169 | 168 | end |
170 | 169 | threads.each(&:join) |
|
176 | 175 | expect(checkout_failed.length).to be >= 10 |
177 | 176 | end |
178 | 177 | end |
| 178 | + # rubocop:enable Naming/VariableName, RSpec/InstanceVariable |
179 | 179 | end |
0 commit comments