Skip to content

Commit

Permalink
Problem: testground no log on failure
Browse files Browse the repository at this point in the history
Solution:
- add exception handling
  • Loading branch information
yihuang committed Sep 16, 2024
1 parent e2b0a65 commit 01d9fa5
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions testground/benchmark/benchmark/stateless.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ def patchimage(toimage, src, dst, fromimage):
@click.option("--cronosd", default=CONTAINER_CRONOSD_PATH)
@click.option("--global-seq", default=None)
def run(outdir: str, datadir: str, cronosd, global_seq):
run_echo_server(ECHO_SERVER_PORT)

datadir = Path(datadir)
cfg = json.loads((datadir / "config.json").read_text())

Expand All @@ -182,9 +180,26 @@ def run(outdir: str, datadir: str, cronosd, global_seq):
group = VALIDATOR_GROUP if global_seq < validators else FULLNODE_GROUP
group_seq = global_seq if group == VALIDATOR_GROUP else global_seq - validators
print("node role", global_seq, group, group_seq)

home = datadir / group / str(group_seq)

try:
return do_run(home, cronosd, group, cfg)
finally:
# collect outputs
output = Path("/data.tar.bz2")
with tarfile.open(output, "x:bz2") as tar:
tar.add(home, arcname="data", filter=output_filter(group, group_seq))
outdir = Path(outdir)
if outdir.exists():
assert outdir.is_dir()
filename = outdir / f"{group}_{group_seq}.tar.bz2"
filename.unlink(missing_ok=True)
shutil.copy(output, filename)


def do_run(home: str, cronosd: str, group: str, cfg: dict):
run_echo_server(ECHO_SERVER_PORT)

# wait for persistent peers to be ready
wait_for_peers(home)

Expand Down Expand Up @@ -215,17 +230,6 @@ def run(outdir: str, datadir: str, cronosd, global_seq):
proc.kill()
proc.wait(20)

# collect outputs
output = Path("/data.tar.bz2")
with tarfile.open(output, "x:bz2") as tar:
tar.add(home, arcname="data", filter=output_filter(group, group_seq))
outdir = Path(outdir)
if outdir.exists():
assert outdir.is_dir()
filename = outdir / f"{group}_{group_seq}.tar.bz2"
filename.unlink(missing_ok=True)
shutil.copy(output, filename)


def output_filter(group, group_seq: int):
"""
Expand Down

0 comments on commit 01d9fa5

Please sign in to comment.