✅ Assertion
By default, Ddosify marks a step result as successful if it sends the request and receives the response without any network errors. Status code or body type (or content) does not affect the success/failure criteria. However, this may not provide a good test result for your use case, and you may want to create your own success/fail logic. That's where Assertions come in.
Ddosify supports assertions on status code
, response body
, response size
, response time
, headers
, and variables
. You can use the assertion
parameter in the config file to check if the response matches the given condition per step. If the condition is not met, Ddosify will fail the step. Check the example config to see how it looks.
As shown in the related table, the first five keywords store different data related to the response. The last keyword, variables
, stores the current state of environment variables for the step. You can use Functions or Operators to build conditional expressions based on these keywords.
You can write multiple assertions for a step. If any assertion fails, the step is marked as failed.
If Ddosify can't receive the response for a request, that step is marked as failed without processing the assertions. You will see a Server Error as the failure reason in the test result instead of an Assertion Error.
Keywords
Keyword | Description | Usage |
---|---|---|
status_code | Status code | - |
body | Response body | - |
response_size | Response size in bytes | - |
response_time | Response time in ms | - |
headers | Response headers | headers.header-key |
variables | Global and captured variables | variables.VarName |
Functions
Function | Parameters | Description |
---|---|---|
less_than | ( param int , limit int ) | checks if param is less than limit |
greater_than | ( param int , limit int ) | checks if param is greater than limit |
exists | ( param any ) | checks if variable exists |
equals | ( param1 any , param2 any ) | checks if given parameters are equal |
equals_on_file | ( param any , file_path string ) | reads from given file path and checks if it equals to given parameter |
in | ( param any , array_param array ) | checks if expression is in given array |
contains | ( param1 any , param2 any ) | makes substring with param1 inside param2 |
not | ( param bool ) | returns converse of given param |
range | ( param int , low int ,high int ) | returns param is in range of [low,high): low is included, high is not included. |
json_path | ( json_path string ) | extracts from response body using given json path |
xpath | ( xpath string ) | extracts from response body using given xml path |
html_path | ( html string ) | extracts from response body using given html path |
regexp | ( param any , regexp string , matchNo int ) | extracts from given value in the first parameter using given regular expression |
Operators
Operator | Description |
---|---|
== | equals |
!= | not equals |
> | greater than |
< | less than |
! | not |
&& | and |
|| | or |
Examples
Expression | Description |
---|---|
less_than(status_code,201) | checks if status code is less than 201 |
equals(status_code,200) | checks if status code equals to 200 |
status_code == 200 | same as preceding one |
not(status_code == 500) | checks if status code not equals to 500 |
status_code != 500 | same as preceding one |
equals(json_path(\"employees.0.name\"),\"Name\") | checks if json extracted value is equal to "Name" |
equals(xpath(\"//item/title\"),\"ABC\") | checks if xml extracted value is equal to "ABC" |
equals(html_path(\"//body/h1\"),\"ABC\") | checks if html extracted value is equal to "ABC" |
equals(variables.x,100) | checks if x variable coming from global or captured variables is equal to 100 |
equals(variables.x,variables.y) | checks if variables x and y are equal to each other |
equals_on_file(body,\"file.json\") | reads from file.json and compares response body with read file |
exists(headers.Content-Type) | checks if content-type header exists in response headers |
contains(body,\"xyz\") | checks if body contains "xyz" in it |
range(headers.content-length,100,300) | checks if content-length header is in range [100,300) |
in(status_code,[200,201]) | checks if status code equal to 200 or 201 |
(status_code == 200) || (status_code == 201) | same as preceding one |
regexp(body,\"[a-z]+_[0-9]+\",0) == \"messi_10\" | checks if matched result from regex is equal to "messi_10" |
Success Criteria (Pass / Fail)
Ddosify supports success criteria, allowing users to verify the success of their load tests based on response times and failure counts of iterations. With this feature, users can assert the percentile of response times and the failure counts of all iterations in a test.
Users can specify the required percentile of response times and failure counts in the configuration file, and the engine will compare the actual response times and failure counts to these values throughout the test continuously. According to the user's configuration, the test can be aborted or continue running until the end. Check the example config to see how the success_criterias
keyword looks.
Note that the functions and operators mentioned in the Step Assertion section can also be utilized for the Success Criteria keywords listed below.
You can see a success criteria example in the examples.
Difference Between Success Criteria and Step Assertions
Unlike assertions focused on individual steps, which determine the success or failure of a step according to its response, Success Criteria create an abort/continue logic for the entire test, which is based on the accumulated data from all iterations.
Keywords
Keyword | Description | Usage |
---|---|---|
fail_count | Failure count of iterations | Used for aborting when test exceeds certain fail_count |
iteration_duration | Response times of iterations in ms | Used for percentile functions |
fail_count_perc | Fail count percentage, in range [0,1] | Used for aborting when test exceeds certain fail count percentage |
Functions
Function | Parameters | Description |
---|---|---|
p99 | ( arr int array ) | 99th percentile, use as p99(iteration_duration) |
p98 | ( arr int array ) | 98th percentile, use as p98(iteration_duration) |
p95 | ( arr int array ) | 95th percentile, use as p95(iteration_duration) |
p90 | ( arr int array ) | 90th percentile, use as p90(iteration_duration) |
p80 | ( arr int array ) | 80th percentile, use as p80(iteration_duration) |
min | ( arr int array ) | returns minimum element |
max | ( arr int array ) | returns maximum element |
avg | ( arr int array ) | calculates and returns average |
Examples
Expression | Description |
---|---|
p95(iteration_duration) < 100 | 95th percentile should be less than 100 ms |
less_than(fail_count,120) | Total fail count should be less than 120 |
less_than(fail_count_perc,0.05) | Fail count percentage should be less than 5% |