Skip to content

Commit 242d06e

Browse files
committed
refactor(tests): inline _check_tx_bandwidth
The function is too small, so inline it. Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
1 parent 427d765 commit 242d06e

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

tests/integration_tests/performance/test_rate_limiter.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ def _check_tx_rate_limiting(test_microvm):
161161

162162
# Second step: check bandwidth when rate limiting is on.
163163
print("Run guest TX iperf for rate limiting without burst")
164-
_check_tx_bandwidth(test_microvm, eth1.host_ip, expected_kbps)
164+
observed_kbps = _get_tx_bandwidth_with_duration(
165+
test_microvm, eth1.host_ip, IPERF_TRANSMIT_TIME
166+
)
167+
assert _diff(observed_kbps, expected_kbps) < MAX_BYTES_DIFF_PERCENTAGE
165168

166169
# Third step: get the number of bytes when rate limiting is on and there is
167170
# an initial burst size from where to consume.
@@ -179,7 +182,10 @@ def _check_tx_rate_limiting(test_microvm):
179182
assert _diff(burst_kbps, expected_kbps) > 100
180183

181184
# Since the burst should be consumed, check rate limit is in place.
182-
_check_tx_bandwidth(test_microvm, eth2.host_ip, expected_kbps)
185+
observed_kbps = _get_tx_bandwidth_with_duration(
186+
test_microvm, eth2.host_ip, IPERF_TRANSMIT_TIME
187+
)
188+
assert _diff(observed_kbps, expected_kbps) < MAX_BYTES_DIFF_PERCENTAGE
183189

184190

185191
def _check_rx_rate_limiting(test_microvm):
@@ -241,11 +247,17 @@ def _check_tx_rate_limit_patch(test_microvm):
241247
# Check that a TX rate limiter can be applied to a previously unlimited
242248
# interface.
243249
_patch_iface_bw(test_microvm, "eth0", "TX", bucket_size, REFILL_TIME_MS)
244-
_check_tx_bandwidth(test_microvm, eth0.host_ip, expected_kbps)
250+
observed_kbps = _get_tx_bandwidth_with_duration(
251+
test_microvm, eth0.host_ip, IPERF_TRANSMIT_TIME
252+
)
253+
assert _diff(observed_kbps, expected_kbps) < MAX_BYTES_DIFF_PERCENTAGE
245254

246255
# Check that a TX rate limiter can be updated.
247256
_patch_iface_bw(test_microvm, "eth1", "TX", bucket_size, REFILL_TIME_MS)
248-
_check_tx_bandwidth(test_microvm, eth1.host_ip, expected_kbps)
257+
observed_kbps = _get_tx_bandwidth_with_duration(
258+
test_microvm, eth1.host_ip, IPERF_TRANSMIT_TIME
259+
)
260+
assert _diff(observed_kbps, expected_kbps) < MAX_BYTES_DIFF_PERCENTAGE
249261

250262
# Check that a TX rate limiter can be removed.
251263
_patch_iface_bw(test_microvm, "eth0", "TX", 0, 0)
@@ -283,15 +295,6 @@ def _check_rx_rate_limit_patch(test_microvm):
283295
assert _diff(rate_no_limit_kbps, expected_kbps) > 50
284296

285297

286-
def _check_tx_bandwidth(test_microvm, ip, expected_kbps):
287-
"""Check that the rate-limited TX bandwidth is close to what we expect."""
288-
observed_kbps = _get_tx_bandwidth_with_duration(
289-
test_microvm, ip, IPERF_TRANSMIT_TIME
290-
)
291-
diff_pc = _diff(observed_kbps, expected_kbps)
292-
assert diff_pc < MAX_BYTES_DIFF_PERCENTAGE
293-
294-
295298
def _get_tx_bandwidth_with_duration(test_microvm, host_ip, duration):
296299
"""Check that the rate-limited TX bandwidth is close to what we expect."""
297300

0 commit comments

Comments
 (0)