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 9f58c5d commit 30b6222
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions locust/test/test_main.py
Expand Up @@ -1436,6 +1436,64 @@ def t(self):
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",
"2s",
"--json"
],
stderr=DEVNULL,
stdout=PIPE,
text=True,
)
stdout, stderr = proc.communicate()
from pprint import pprint
pprint(stderr)
pprint(stdout)

try:
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(2 , result["num_requests"])
self.assertEqual(0 , 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 30b6222

Please sign in to comment.