Skip to content

Commit 4533de7

Browse files
ShadowCurseroypat
authored andcommitted
refactor(tests): rename _get_percentage_difference into _diff
With shorter name we can inline some functions in the next commit. Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent edf6d1c commit 4533de7

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

tests/integration_tests/performance/test_rate_limiter.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def _check_tx_rate_limiting(test_microvm):
157157

158158
# Sanity check that bandwidth with no rate limiting is at least double
159159
# than the one expected when rate limiting is in place.
160-
assert _get_percentage_difference(rate_no_limit_kbps, expected_kbps) > 100
160+
assert _diff(rate_no_limit_kbps, expected_kbps) > 100
161161

162162
# Second step: check bandwidth when rate limiting is on.
163163
print("Run guest TX iperf for rate limiting without burst")
@@ -176,7 +176,7 @@ def _check_tx_rate_limiting(test_microvm):
176176
_, burst_kbps = _process_iperf_output(iperf_out)
177177
print("TX burst_kbps: {}".format(burst_kbps))
178178
# Test that the burst bandwidth is at least as two times the rate limit.
179-
assert _get_percentage_difference(burst_kbps, expected_kbps) > 100
179+
assert _diff(burst_kbps, expected_kbps) > 100
180180

181181
# Since the burst should be consumed, check rate limit is in place.
182182
_check_tx_bandwidth(test_microvm, eth2.host_ip, expected_kbps)
@@ -203,7 +203,7 @@ def _check_rx_rate_limiting(test_microvm):
203203

204204
# Sanity check that bandwidth with no rate limiting is at least double
205205
# than the one expected when rate limiting is in place.
206-
assert _get_percentage_difference(rate_no_limit_kbps, expected_kbps) > 100
206+
assert _diff(rate_no_limit_kbps, expected_kbps) > 100
207207

208208
# Second step: check bandwidth when rate limiting is on.
209209
print("Run guest RX iperf for rate limiting without burst")
@@ -225,7 +225,7 @@ def _check_rx_rate_limiting(test_microvm):
225225
_, burst_kbps = _process_iperf_output(iperf_out)
226226
print("RX burst_kbps: {}".format(burst_kbps))
227227
# Test that the burst bandwidth is at least as two times the rate limit.
228-
assert _get_percentage_difference(burst_kbps, expected_kbps) > 100
228+
assert _diff(burst_kbps, expected_kbps) > 100
229229

230230
# Since the burst should be consumed, check rate limit is in place.
231231
_check_rx_bandwidth(test_microvm, eth2.guest_ip, expected_kbps)
@@ -254,7 +254,7 @@ def _check_tx_rate_limit_patch(test_microvm):
254254
)
255255
# Check that bandwidth when rate-limit disabled is at least 1.5x larger
256256
# than the one when rate limiting was enabled.
257-
assert _get_percentage_difference(rate_no_limit_kbps, expected_kbps) > 50
257+
assert _diff(rate_no_limit_kbps, expected_kbps) > 50
258258

259259

260260
def _check_rx_rate_limit_patch(test_microvm):
@@ -280,15 +280,15 @@ def _check_rx_rate_limit_patch(test_microvm):
280280
)
281281
# Check that bandwidth when rate-limit disabled is at least 1.5x larger
282282
# than the one when rate limiting was enabled.
283-
assert _get_percentage_difference(rate_no_limit_kbps, expected_kbps) > 50
283+
assert _diff(rate_no_limit_kbps, expected_kbps) > 50
284284

285285

286286
def _check_tx_bandwidth(test_microvm, ip, expected_kbps):
287287
"""Check that the rate-limited TX bandwidth is close to what we expect."""
288288
observed_kbps = _get_tx_bandwidth_with_duration(
289289
test_microvm, ip, IPERF_TRANSMIT_TIME
290290
)
291-
diff_pc = _get_percentage_difference(observed_kbps, expected_kbps)
291+
diff_pc = _diff(observed_kbps, expected_kbps)
292292
assert diff_pc < MAX_BYTES_DIFF_PERCENTAGE
293293

294294

@@ -311,7 +311,7 @@ def _check_rx_bandwidth(test_microvm, ip, expected_kbps):
311311
observed_kbps = _get_rx_bandwidth_with_duration(
312312
test_microvm, ip, IPERF_TRANSMIT_TIME
313313
)
314-
diff_pc = _get_percentage_difference(observed_kbps, expected_kbps)
314+
diff_pc = _diff(observed_kbps, expected_kbps)
315315
assert diff_pc < MAX_BYTES_DIFF_PERCENTAGE
316316

317317

@@ -395,7 +395,7 @@ def _run_iperf_on_host(iperf_cmd, test_microvm):
395395
return stdout
396396

397397

398-
def _get_percentage_difference(measured, base):
398+
def _diff(measured, base):
399399
"""Return the percentage delta between the arguments."""
400400
assert base != 0
401401
return (abs(measured - base) / base) * 100.0

0 commit comments

Comments
 (0)