Skip to content

Commit

Permalink
tests: enable load test (#821)
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-khimov authored Jun 28, 2024
2 parents ecf2704 + 11cf95c commit ea51fff
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 472 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,20 @@ jobs:
sudo chmod a+x neofs-s3-gw
working-directory: neofs-testcases

- name: Checkout xk6-neofs repository
uses: actions/checkout@v4
with:
repository: nspcc-dev/xk6-neofs
ref: master
path: xk6-neofs

- name: Build xk6-neofs
timeout-minutes: 5
run: |
make install_xk6
make build
working-directory: xk6-neofs

- name: Prepare venv
id: prepare_venv
timeout-minutes: 30
Expand Down
82 changes: 82 additions & 0 deletions neofs-testlib/neofs_testlib/env/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import pickle
import random
import shutil
import socket
import stat
import string
Expand Down Expand Up @@ -865,3 +866,84 @@ def _launch_process(self):
stderr=stderr_fp,
env=rest_gw_env,
)


class XK6:
def __init__(self, neofs_env: NeoFSEnv):
self.neofs_env = neofs_env
self.xk6_dir = os.getenv("XK6_DIR", "../xk6-neofs")
self.wallet = NodeWallet(
path=NeoFSEnv._generate_temp_file(prefix="xk6_wallet"),
address="",
password=self.neofs_env.default_password,
)
self.neofs_env.generate_storage_wallet(self.wallet, label="xk6")
self.config = neofs_env.generate_cli_config(self.wallet)

@allure.step("Run K6 Loader")
def run(
self,
endpoints: list[str],
out="grpc.json",
duration=30,
write_obj_size=8192,
readers=2,
writers=2,
registry_file="registry.bolt",
scenario="grpc.js",
):
if not os.path.exists(self.xk6_dir):
raise RuntimeError("Invalid xk6 directory")
command = (
f"{self.xk6_dir}/xk6-neofs "
f"run "
f"-e DURATION={duration} "
f"-e WRITE_OBJ_SIZE={write_obj_size} "
f"-e READERS={readers} "
f"-e WRITERS={writers} "
f"-e REGISTRY_FILE={registry_file} "
f"-e GRPC_ENDPOINTS={endpoints[0]} "
f"-e PREGEN_JSON={out} "
f"{self.xk6_dir}/scenarios/{scenario} "
)
result = self.neofs_env.shell.exec(command)
assert not result.return_code, "RC after k6 load is not zero"
assert "neofs_obj_get_fails" not in result.stdout, "some GET requests failed, see logs"
assert "neofs_obj_put_fails" not in result.stdout, "some PUT requests failed, see logs"

@allure.step("Prepare containers and objects for k6 load run")
def prepare(
self,
endpoints: list[str],
size=1024,
containers=1,
out="grpc.json",
preload_obj=250,
policy="REP 2 IN X CBF 1 SELECT 2 FROM * AS X",
workers=2,
):
if not os.path.exists(self.xk6_dir):
raise RuntimeError("Invalid xk6 directory")

command = (
f"{self.xk6_dir}/scenarios/preset/preset_grpc.py "
f"--size {size} "
f"--containers {containers} "
f"--out {out} "
f"--endpoint {endpoints[0]} "
f"--preload_obj {preload_obj} "
f'--policy "{policy}" '
f"--wallet {self.wallet.path} "
f"--config {self.config} "
f"--workers {workers} "
)
result = self.neofs_env.shell.exec(command)
assert not result.return_code, "RC after k6 prepare script is not zero"
assert (
f"Total Containers has been created: {containers}" in result.stdout
), "Prepare script didn't create requested containers"
assert (
f"Total Objects has been created: {preload_obj}" in result.stdout
), "Prepare script didn't create requested objects"

shutil.copy(out, os.path.join(self.xk6_dir, "scenarios"))
1 change: 1 addition & 0 deletions neofs-testlib/neofs_testlib/env/templates/network.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ storage:
s3: {{ default_password }}
http: {{ default_password }}
rest: {{ default_password }}
xk6: {{ default_password }}
Loading

0 comments on commit ea51fff

Please sign in to comment.