Skip to content

Commit 1678213

Browse files
committed
add ref_url
1 parent 8967008 commit 1678213

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

chainbench/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ 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("--ref-url", default=None, help="Reference Node URL for retrieving test data before test starts. If not specified, target url is used instead.")
213214
@click.pass_context
214215
def start(
215216
ctx: Context,
@@ -243,6 +244,7 @@ def start(
243244
use_latest_blocks: bool,
244245
size: str | None,
245246
method: str | None = None,
247+
ref_url: str | None = None,
246248
) -> None:
247249
if notify:
248250
click.echo(f"Notify when test is finished using topic: {notify}")
@@ -280,7 +282,7 @@ def start(
280282

281283
user_classes = {}
282284
for locustfile in parse_locustfile_paths([final_profile_path.__str__()]):
283-
_, _user_classes, _ = load_locustfile(locustfile)
285+
_user_classes, _ = load_locustfile(locustfile)
284286
for key, value in _user_classes.items():
285287
user_classes[key] = value
286288
test_data_types = set()
@@ -379,6 +381,7 @@ def start(
379381
method=method,
380382
enable_class_picker=enable_class_picker,
381383
batch_size=batch_size,
384+
ref_url=ref_url,
382385
)
383386
# Start the Locust master
384387
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: 17 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="Set the reference node url to be used for retrieving test data before test starts. If empty, defaults to target url.",
5259
include_in_web_ui=True,
5360
)
5461

@@ -187,15 +194,15 @@ 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 = environment.parsed_options.ref_url if environment.parsed_options.ref_url is not None else environment.host
199+
user_test_data.init_http_client(ref_node_url)
200+
if isinstance(user_test_data, EvmTestData):
201+
chain_id: ChainId = user_test_data.fetch_chain_id()
202+
user_test_data.init_network(chain_id)
203+
logger.info(f"Target endpoint network is {user_test_data.network.name}")
204+
print(f"Target endpoint network is {user_test_data.network.name}")
205+
test_data["chain_id"] = {test_data_class_name: chain_id}
199206
user_test_data.init_data(environment.parsed_options)
200207
test_data[test_data_class_name] = user_test_data.data.to_json()
201208
send_msg_to_workers(environment.runner, "test_data", test_data)

0 commit comments

Comments
 (0)