Skip to content

Commit 16dc35d

Browse files
authored
Add ref-url for fetching test data (#113)
* add ref_url * Update README.md * update dependencies
1 parent 8967008 commit 16dc35d

File tree

8 files changed

+865
-740
lines changed

8 files changed

+865
-740
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repos:
1010
- id: mypy
1111
language_version: python3.10
1212
- repo: https://github.com/python-poetry/poetry
13-
rev: 2.0.1
13+
rev: 2.1.3
1414
hooks:
1515
- id: poetry-check
1616
- repo: https://github.com/pycqa/flake8

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# build stage
2-
FROM python:3.10-buster AS venv
2+
FROM python:3.10-bookworm AS venv
33

44
# copy files
55
COPY pyproject.toml poetry.lock ./
@@ -14,7 +14,7 @@ RUN python -m venv --copies /app/venv
1414
RUN . /app/venv/bin/activate && $HOME/.local/bin/poetry install --no-directory --without dev --no-root --compile
1515

1616
# runtime stage
17-
FROM python:3.10-slim-buster as prod
17+
FROM python:3.10-slim-bookworm as prod
1818

1919
COPY --from=venv /app/venv /app/venv/
2020
ENV PATH /app/venv/bin:$PATH

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ This will run a load test with a general BSC profile.
127127
- `--use-latest-blocks`: Use latest blocks for test data generation and runs a background process to update the test data with latest blocks.
128128
- `--size`: Specifies the test data size. Available values are XS, S, M, L, XL. Default is S.
129129
- `--batch`: Runs the test using batch requests. This will send multiple requests in a single batch request. The number of requests in a batch can be specified using the `--batch-size` flag. Default batch size is 10.
130+
- `--ref-url`: Specifies the reference blockchain node URL that will be used to fetch test data from before the benchmark starts.
130131

131132
You may also run `chainbench start --help` for the full list of parameters and flags.
132133

chainbench/main.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ def validate_profile_path(ctx: Context, param: Parameter, value: str) -> str:
210210
@click.option("--pg-password", default=None, help="PG password")
211211
@click.option("--use-latest-blocks", is_flag=True, help="Uses latest blocks for test data")
212212
@click.option("--size", default=None, help="Set the size of the test data. e.g. --size S")
213+
@click.option(
214+
"--ref-url",
215+
default=None,
216+
help="Reference Node URL for retrieving test data before test starts. If not specified, target url is used.",
217+
)
213218
@click.pass_context
214219
def start(
215220
ctx: Context,
@@ -243,6 +248,7 @@ def start(
243248
use_latest_blocks: bool,
244249
size: str | None,
245250
method: str | None = None,
251+
ref_url: str | None = None,
246252
) -> None:
247253
if notify:
248254
click.echo(f"Notify when test is finished using topic: {notify}")
@@ -280,7 +286,7 @@ def start(
280286

281287
user_classes = {}
282288
for locustfile in parse_locustfile_paths([final_profile_path.__str__()]):
283-
_, _user_classes, _ = load_locustfile(locustfile)
289+
_user_classes, _ = load_locustfile(locustfile)
284290
for key, value in _user_classes.items():
285291
user_classes[key] = value
286292
test_data_types = set()
@@ -379,6 +385,7 @@ def start(
379385
method=method,
380386
enable_class_picker=enable_class_picker,
381387
batch_size=batch_size,
388+
ref_url=ref_url,
382389
)
383390
# Start the Locust master
384391
master_command = locust_options.get_master_command()

chainbench/util/cli.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class LocustOptions:
144144
method: str | None = None
145145
enable_class_picker: bool = False
146146
batch_size: int | None = None
147+
ref_url: str | None = None
147148

148149
def get_master_command(self) -> str:
149150
"""Generate master command."""
@@ -203,6 +204,9 @@ def get_extra_options(self, command: str):
203204

204205
if self.batch_size is not None:
205206
command += f" --batch-size {self.batch_size}"
207+
208+
if self.ref_url is not None:
209+
command += f" --ref-url {self.ref_url}"
206210
return command
207211

208212

chainbench/util/event.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def cli_custom_arguments(parser: LocustArgumentParser):
3131
"--size",
3232
type=str,
3333
default=None,
34-
help="Set the size of the test data. e.g. --size S",
34+
help="Set the size of the test data. e.g. --size S.",
3535
include_in_web_ui=False,
3636
)
3737
parser.add_argument(
@@ -48,7 +48,14 @@ def cli_custom_arguments(parser: LocustArgumentParser):
4848
type=str,
4949
default="eth_blockNumber",
5050
choices=list(all_methods.keys()),
51-
help="Test a specific method",
51+
help="Test a specific method.",
52+
include_in_web_ui=True,
53+
)
54+
parser.add_argument(
55+
"--ref-url",
56+
type=str,
57+
default=None,
58+
help="Reference node url used for fetching test data before test starts. If empty, defaults to target url.",
5259
include_in_web_ui=True,
5360
)
5461

@@ -187,15 +194,20 @@ def on_init(environment: Environment, **_kwargs):
187194
continue
188195
logger.info(f"Initializing test data for {test_data_class_name}")
189196
print(f"Initializing test data for {test_data_class_name}")
190-
if environment.host:
191-
user_test_data.init_http_client(environment.host)
192-
if isinstance(user_test_data, EvmTestData):
193-
chain_id: ChainId = user_test_data.fetch_chain_id()
194-
user_test_data.init_network(chain_id)
195-
logger.info(f"Target endpoint network is {user_test_data.network.name}")
196-
print(f"Target endpoint network is {user_test_data.network.name}")
197-
test_data["chain_id"] = {test_data_class_name: chain_id}
198197
if environment.parsed_options:
198+
ref_node_url = (
199+
environment.parsed_options.ref_url
200+
if environment.parsed_options.ref_url is not None
201+
else environment.host
202+
)
203+
if ref_node_url is not None:
204+
user_test_data.init_http_client(ref_node_url)
205+
if isinstance(user_test_data, EvmTestData):
206+
chain_id: ChainId = user_test_data.fetch_chain_id()
207+
user_test_data.init_network(chain_id)
208+
logger.info(f"Target endpoint network is {user_test_data.network.name}")
209+
print(f"Target endpoint network is {user_test_data.network.name}")
210+
test_data["chain_id"] = {test_data_class_name: chain_id}
199211
user_test_data.init_data(environment.parsed_options)
200212
test_data[test_data_class_name] = user_test_data.data.to_json()
201213
send_msg_to_workers(environment.runner, "test_data", test_data)

0 commit comments

Comments
 (0)