systeminit / si

The System Initiative software
https://systeminit.com
Apache License 2.0
1.58k stars 261 forks source link

Feat/implement load profile api testing #4514

Closed johnrwatson closed 2 months ago

johnrwatson commented 2 months ago

Introducing, the workspace destroyer:

Adds and implements new load testing named parameters to the API testing framework

deno run --allow-env --allow-net --allow-read=. main.ts \
--workspaceId abc \
--userId def \
--password ghi \
--profile '{"Duration": "5", "Requests": "5"}' \
--tests create_and_use_variant

Where the profile dictates how many requests to send per second, over which span duration. I.e. 60s duration with 120 requests is 2 req/s

Output when using profiled execution mode looks as follows, pulsing back an update everytime a request is fired off or the promise lands back in the app:

Triggered: [===            ] 20.00% (1/5) | Completed: [               ] 0.00% (0/5) | Remaining Time: 4s
Triggered: [======         ] 40.00% (2/5) | Completed: [               ] 0.00% (0/5) | Remaining Time: 3s
Triggered: [=========      ] 60.00% (3/5) | Completed: [               ] 0.00% (0/5) | Remaining Time: 2s
Triggered: [============   ] 80.00% (4/5) | Completed: [               ] 0.00% (0/5) | Remaining Time: 1s
Triggered: [===============] 100.00% (5/5) | Completed: [               ] 0.00% (0/5) | Remaining Time: 0s
Triggered: [===============] 100.00% (5/5) | Completed: [===            ] 20.00% (1/5) | Remaining Time: 0s
Triggered: [===============] 100.00% (5/5) | Completed: [======         ] 40.00% (2/5) | Remaining Time: 0s
Triggered: [===============] 100.00% (5/5) | Completed: [=========      ] 60.00% (3/5) | Remaining Time: 0s
Triggered: [===============] 100.00% (5/5) | Completed: [============   ] 80.00% (4/5) | Remaining Time: 0s
Triggered: [===============] 100.00% (5/5) | Completed: [===============] 100.00% (5/5) | Remaining Time: 0s
~~ FINAL REPORT GENERATED ~~
Test Report:
[
  {
    "test_name": "create_and_use_variant",
    "start_time": "2024-09-06T19:54:32.680Z",
    "finish_time": "2024-09-06T19:54:45.767Z",
    "test_duration": "13087ms",
    "test_result": "success",
    "message": "",
    "test_execution_sequence": 1,
    "uuid": "8d69d965-0ec2-40a9-84d2-208a8501d7ad"
  },
  {
    "test_name": "create_and_use_variant",
    "start_time": "2024-09-06T19:54:35.685Z",
    "finish_time": "2024-09-06T19:54:55.546Z",
    "test_duration": "19861ms",
    "test_result": "success",
    "message": "",
    "test_execution_sequence": 4,
    "uuid": "54d8b9a5-eb26-42d1-8fa0-17f8523a817c"
  },
  {
    "test_name": "create_and_use_variant",
    "start_time": "2024-09-06T19:54:36.688Z",
    "finish_time": "2024-09-06T19:54:59.459Z",
    "test_duration": "22771ms",
    "test_result": "success",
    "message": "",
    "test_execution_sequence": 5,
    "uuid": "2b64181b-69c6-4a7a-8561-f4f1c8b948a6"
  },
  {
    "test_name": "create_and_use_variant",
    "start_time": "2024-09-06T19:54:33.683Z",
    "finish_time": "2024-09-06T19:54:59.678Z",
    "test_duration": "25995ms",
    "test_result": "success",
    "message": "",
    "test_execution_sequence": 2,
    "uuid": "078cc906-7e20-4713-83db-68810890039f"
  },
  {
    "test_name": "create_and_use_variant",
    "start_time": "2024-09-06T19:54:34.684Z",
    "finish_time": "2024-09-06T19:54:59.848Z",
    "test_duration": "25164ms",
    "test_result": "success",
    "message": "",
    "test_execution_sequence": 3,
    "uuid": "61221903-008c-4c22-8ab8-276356576924"
  }
]

Also adds the api tests to execute as part of the normal deployment steps.

Note: This code isn't perfect, but it's perfectly functional to do the job in both one-shot and profiled execution modes. We can come back and tidy some bits up as we move forward.