Skip to content

Commit 8bb216d

Browse files
Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 3166677 commit 8bb216d

1 file changed

Lines changed: 57 additions & 10 deletions

File tree

spec/integration/sdam_prose_spec.rb

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,27 +85,72 @@
8585

8686
after do
8787
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
92117
end
93118

94119
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(
97142
setParameter: 1,
98143
ingressConnectionEstablishmentRateLimiterEnabled: true,
99144
)
100-
root_authorized_client.use('admin').database.command(
145+
admin_db.command(
101146
setParameter: 1,
102147
ingressConnectionEstablishmentRatePerSec: 20,
103148
)
104-
root_authorized_client.use('admin').database.command(
149+
admin_db.command(
105150
setParameter: 1,
106151
ingressConnectionEstablishmentBurstCapacitySecs: 1,
107152
)
108-
root_authorized_client.use('admin').database.command(
153+
admin_db.command(
109154
setParameter: 1,
110155
ingressConnectionEstablishmentMaxQueueDepth: 1,
111156
)
@@ -121,7 +166,9 @@
121166
client.use('test')['test'].find(
122167
'$where' => 'function() { sleep(2000); return true; }'
123168
).first
124-
rescue StandardError
169+
rescue Mongo::Error::PoolTimeout,
170+
Mongo::Error::SocketError,
171+
Mongo::Error::NoServerAvailable
125172
# Ignore connection errors (including checkout timeouts).
126173
end
127174
end

0 commit comments

Comments
 (0)