-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rptest/utils: factor out rate testing util
Used here for asserting that producer rate goes to zero when we block writes due to low space. Turns out this is also a handy utility for testing other features like quotas. Generalize and factor out a new test helper class ExpectRate. See the docstring for implementation details.
- Loading branch information
Aaron Fabbri
committed
Jun 23, 2022
1 parent
f5aec8b
commit 024eab8
Showing
2 changed files
with
117 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# Copyright 2022 Redpanda Data, Inc. | ||
# | ||
# Use of this software is governed by the Business Source License | ||
# included in the file licenses/BSL.md | ||
# | ||
# As of the Change Date specified in that file, in accordance with | ||
# the Business Source License, use of this software will be governed | ||
# by the Apache License, Version 2.0 | ||
|
||
from logging import Logger | ||
from time import sleep, time_ns | ||
from typing import Callable, NamedTuple | ||
|
||
|
||
class RateTarget(NamedTuple): | ||
max_total_sec: int | ||
target_sec: int | ||
# rates in counter/sec | ||
target_min_rate: int | ||
target_max_rate: int | ||
|
||
|
||
class CounterMeasurement(NamedTuple): | ||
count: int | ||
timestamp: int | ||
|
||
|
||
def time_ms() -> int: | ||
return time_ns() // 10**6 | ||
|
||
|
||
def sleep_ms(msec: int) -> None: | ||
sleep(msec / 1000) | ||
|
||
|
||
class ExpectRate: | ||
"""Measure observed counter (e.g. bytes) rate, until: | ||
- Fail: We exceed max total duration: Throw an exception. | ||
- Success: We achieve target rate for at least the min measured duration. | ||
--- time ---> | ||
.''''''''''''''''''''''''''''''''''''. | ||
| total duration | | ||
:'''''''''''''''''''''''''''''''''''': | ||