Skip to content

Commit

Permalink
feat(tests, scale): add csv reporting
Browse files Browse the repository at this point in the history
Signed-off-by: Fatih Acar <[email protected]>
  • Loading branch information
fatih-acar committed Feb 15, 2024
1 parent c2e3945 commit 9e24b9f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ retype.manifest
storage/*
.coverage.*
python_sdk/dist/*
.benchmarks/*
.benchmarks/*

# Test reports
**/*.csv
23 changes: 14 additions & 9 deletions backend/tests/scale/common/users.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import time

from infrahub_sdk import Config
from locust import HttpUser, User, task

Expand Down Expand Up @@ -33,16 +35,19 @@ def __init__(self, environment):

@task
def crud(self):
objects = self.client.all(kind="InfraNode", limit=50)
begin = time.time()
# Run for at least 5 minutes
while time.time() < begin + 300:
objects = self.client.all(kind="InfraNode", limit=50)

if len(objects) >= 2:
delete_this_node, update_this_node = objects[0:2]
if len(objects) >= 2:
delete_this_node, update_this_node = objects[0:2]

obj = self.client.create(kind="InfraNode", data={"name": random_ascii_string()})
obj.save()
obj = self.client.create(kind="InfraNode", data={"name": random_ascii_string()})
obj.save()

if len(objects) >= 2:
update_this_node.name.value = random_ascii_string()
update_this_node.save()
if len(objects) >= 2:
update_this_node.name.value = random_ascii_string()
update_this_node.save()

delete_this_node.delete()
delete_this_node.delete()
6 changes: 6 additions & 0 deletions backend/tests/scale/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import common.events
import common.stagers
import common.users
import gevent
from common.config import Config as ScaleTestConfig
from infrahub_sdk import Config, InfrahubClientSync
from locust import events
from locust.env import Environment
from locust.stats import PERCENTILES_TO_REPORT, StatsCSVFileWriter

config = ScaleTestConfig()

Expand Down Expand Up @@ -97,6 +99,10 @@ def main(schema: Path, stager: str, amount: int, attrs: int, rels: int, test: st
print("--- starting test")
env = Environment(user_classes=[user_class], events=events)
runner = env.create_local_runner()

stats_csv_writer = StatsCSVFileWriter(env, PERCENTILES_TO_REPORT, str(time.time()), True)
gevent.spawn(stats_csv_writer.stats_writer)

runner.start(1, spawn_rate=1)
runner.greenlet.join()

Expand Down

0 comments on commit 9e24b9f

Please sign in to comment.