|
85 | 85 |
|
86 | 86 | after do |
87 | 87 | sleep 1 |
88 | | - root_authorized_client.use('admin').database.command( |
89 | | - setParameter: 1, |
90 | | - ingressConnectionEstablishmentRateLimiterEnabled: false, |
91 | | - ) |
| 88 | + admin_db = root_authorized_client.use('admin').database |
| 89 | + |
| 90 | + if defined?(@prev_ingressConnectionEstablishmentRateLimiterEnabled) && |
| 91 | + defined?(@prev_ingressConnectionEstablishmentRatePerSec) && |
| 92 | + defined?(@prev_ingressConnectionEstablishmentBurstCapacitySecs) && |
| 93 | + defined?(@prev_ingressConnectionEstablishmentMaxQueueDepth) |
| 94 | + admin_db.command( |
| 95 | + setParameter: 1, |
| 96 | + ingressConnectionEstablishmentRateLimiterEnabled: @prev_ingressConnectionEstablishmentRateLimiterEnabled, |
| 97 | + ) |
| 98 | + admin_db.command( |
| 99 | + setParameter: 1, |
| 100 | + ingressConnectionEstablishmentRatePerSec: @prev_ingressConnectionEstablishmentRatePerSec, |
| 101 | + ) |
| 102 | + admin_db.command( |
| 103 | + setParameter: 1, |
| 104 | + ingressConnectionEstablishmentBurstCapacitySecs: @prev_ingressConnectionEstablishmentBurstCapacitySecs, |
| 105 | + ) |
| 106 | + admin_db.command( |
| 107 | + setParameter: 1, |
| 108 | + ingressConnectionEstablishmentMaxQueueDepth: @prev_ingressConnectionEstablishmentMaxQueueDepth, |
| 109 | + ) |
| 110 | + else |
| 111 | + # Fallback: at least disable the limiter if previous values were not captured. |
| 112 | + admin_db.command( |
| 113 | + setParameter: 1, |
| 114 | + ingressConnectionEstablishmentRateLimiterEnabled: false, |
| 115 | + ) |
| 116 | + end |
92 | 117 | end |
93 | 118 |
|
94 | 119 | it 'generates checkout failures when the ingress connection rate limiter is active' do |
95 | | - # Enable the ingress rate limiter. |
96 | | - root_authorized_client.use('admin').database.command( |
| 120 | + admin_db = root_authorized_client.use('admin').database |
| 121 | + |
| 122 | + # Capture current ingress connection establishment parameters so they can be restored. |
| 123 | + current_params = admin_db.command( |
| 124 | + getParameter: 1, |
| 125 | + ingressConnectionEstablishmentRateLimiterEnabled: 1, |
| 126 | + ingressConnectionEstablishmentRatePerSec: 1, |
| 127 | + ingressConnectionEstablishmentBurstCapacitySecs: 1, |
| 128 | + ingressConnectionEstablishmentMaxQueueDepth: 1, |
| 129 | + ).first |
| 130 | + |
| 131 | + @prev_ingressConnectionEstablishmentRateLimiterEnabled = |
| 132 | + current_params['ingressConnectionEstablishmentRateLimiterEnabled'] |
| 133 | + @prev_ingressConnectionEstablishmentRatePerSec = |
| 134 | + current_params['ingressConnectionEstablishmentRatePerSec'] |
| 135 | + @prev_ingressConnectionEstablishmentBurstCapacitySecs = |
| 136 | + current_params['ingressConnectionEstablishmentBurstCapacitySecs'] |
| 137 | + @prev_ingressConnectionEstablishmentMaxQueueDepth = |
| 138 | + current_params['ingressConnectionEstablishmentMaxQueueDepth'] |
| 139 | + |
| 140 | + # Enable the ingress rate limiter with test-specific values. |
| 141 | + admin_db.command( |
97 | 142 | setParameter: 1, |
98 | 143 | ingressConnectionEstablishmentRateLimiterEnabled: true, |
99 | 144 | ) |
100 | | - root_authorized_client.use('admin').database.command( |
| 145 | + admin_db.command( |
101 | 146 | setParameter: 1, |
102 | 147 | ingressConnectionEstablishmentRatePerSec: 20, |
103 | 148 | ) |
104 | | - root_authorized_client.use('admin').database.command( |
| 149 | + admin_db.command( |
105 | 150 | setParameter: 1, |
106 | 151 | ingressConnectionEstablishmentBurstCapacitySecs: 1, |
107 | 152 | ) |
108 | | - root_authorized_client.use('admin').database.command( |
| 153 | + admin_db.command( |
109 | 154 | setParameter: 1, |
110 | 155 | ingressConnectionEstablishmentMaxQueueDepth: 1, |
111 | 156 | ) |
|
121 | 166 | client.use('test')['test'].find( |
122 | 167 | '$where' => 'function() { sleep(2000); return true; }' |
123 | 168 | ).first |
124 | | - rescue StandardError |
| 169 | + rescue Mongo::Error::PoolTimeout, |
| 170 | + Mongo::Error::SocketError, |
| 171 | + Mongo::Error::NoServerAvailable |
125 | 172 | # Ignore connection errors (including checkout timeouts). |
126 | 173 | end |
127 | 174 | end |
|
0 commit comments