Skip to content

Commit

Permalink
json schema integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersSpringborg committed Dec 27, 2022
1 parent aaf164a commit a70b3b5
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions locust/test/test_main.py
Expand Up @@ -1414,16 +1414,49 @@ def t(self):
pass
"""
)
with mock_locustfile(content=LOCUSTFILE_CONTENT) as mocked:
proc = subprocess.Popen(
["locust", "-f", mocked.file_path, "--headless", "-t", "5s", "--json"],
stderr=DEVNULL,
stdout=PIPE,
text=True,
)
stdout, stderr = proc.communicate()

try:
json.loads(stdout)
except json.JSONDecodeError:
self.fail(f"Trying to parse {stdout} as json failed")
self.assertEqual(0, proc.returncode)

def test_json_schema(self):
LOCUSTFILE_CONTENT = textwrap.dedent(
"""
from locust import HttpUser, task, constant
class QuickstartUser(HttpUser):
wait_time = constant(1)
@task
def hello_world(self):
self.client.get("/")
"""
)
with mock_locustfile(content=LOCUSTFILE_CONTENT) as mocked:
proc = subprocess.Popen(
[
"locust",
"-f",
mocked.file_path,
"--host",
"http://google.com",
"--headless",
"-u",
"1",
"-t",
"5s",
"--json"
"2s",
"--json",
],
stderr=DEVNULL,
stdout=PIPE,
Expand All @@ -1432,11 +1465,25 @@ def t(self):
stdout, stderr = proc.communicate()

try:
json.loads(stdout)
data = json.loads(stdout)
except json.JSONDecodeError:
self.fail(f"Trying to parse {stdout} as json failed")

self.assertEqual(0, proc.returncode)

result = data[0]
self.assertEqual(float, type(result["last_request_timestamp"]))
self.assertEqual(float, type(result["start_time"]))
self.assertEqual(int, type(result["num_requests"]))
self.assertEqual(int, type(result["num_none_requests"]))
self.assertEqual(float, type(result["total_response_time"]))
self.assertEqual(float, type(result["max_response_time"]))
self.assertEqual(float, type(result["min_response_time"]))
self.assertEqual(int, type(result["total_content_length"]))
self.assertEqual(dict, type(result["response_times"]))
self.assertEqual(dict, type(result["num_reqs_per_sec"]))
self.assertEqual(dict, type(result["num_fail_per_sec"]))

def test_worker_indexes(self):
content = """
from locust import HttpUser, task, between
Expand Down

0 comments on commit a70b3b5

Please sign in to comment.