Skip to content

Commit

Permalink
Multiple Version asserts with drill
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyGiorgio committed Sep 24, 2023
1 parent 44e9fcf commit 2451e70
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 7 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ You need a postgres database and an authentication key. These can be set in the
and `AUTH_KEY` respectively. This can be set in a `.env` file in the root of the project.

To run the server, run `cargo run --release` in the root of the project.

## Stress testing

```
AUTH_TOKEN=ey... drill --benchmark drill.yml -o 30
```
175 changes: 168 additions & 7 deletions drill.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
base: 'https://vss-staging.fly.dev'
concurrency: 250
concurrency: 125
iterations: 2000

plan:
Expand All @@ -8,20 +8,181 @@ plan:
method: GET
url: /health-check

- name: Put Objects
# Generate a random UUID and assign it to the test_key variable
- name: Generate unique test key
exec:
command: "echo \"drill_test_$(uuidgen)\""
assign: test_key

# Get the Object to fetch the initial version
- name: Get Object Initial (1) - '{{ test_key }}'
request:
method: POST
url: /getObject
body: '{"key": "{{ test_key }}"}'
headers:
Content-Type: 'application/json'
Authorization: Bearer {{ AUTH_TOKEN }}
assign: initial_get_object_response

- name: Extract and increment version (1) - '{{ test_key }}'
exec:
command: "input='{{ initial_get_object_response.body }}'; [ -z \"$input\" ] && echo 0 || echo \"$input\" | jq '.version? // empty | if type == \"number\" then . + 1 else 0 end'"
assign: version

- name: Put Objects (1) - '{{ test_key }}'
request:
method: PUT
url: /putObjects
body: '{"transaction_items": [{"key": "key", "value": [0, 1, 2], "version": 0}]}'
body: '{"transaction_items": [{"key": "{{ test_key }}", "value": [0, 1, 2], "version": {{ version }} }]}'
headers:
Content-Type: 'application/json'
Authorization: Bearer eyJhbGciOiJFUzI1NksiLCJraWQiOiIwMzU0N2Q5MmI2MTg4NTZmNGVkYTg0YTY0ZWMzMmYxNjk0Yzk2MDhhM2Y5ZGM3M2U5MWYwOGI1ZGFhMDg3MjYwMTYifQ.eyJleHAiOjE2OTU0NTc4MjgsIm5iZiI6MTY5NTQ1MDYyOCwiaWF0IjoxNjk1NDU0MjI4LCJzdWIiOiIwMjlhOGYwY2MxZWNmZDU5NWNjNzQyYWU5OGU4NDZlNDRjODdmMWJjYWVjNzcxOTZhOTc3MzFjNzllMmJmZDI1ODUifQ.llJlMub-FWU9tgmQRMchziyg6jLGOgKYPq5DOm4dOGUqMCtDyRQX--ILBLhgkHTVhTy0EFyYu0x4clVcb7kV0A
Authorization: Bearer {{ AUTH_TOKEN }}

- name: Get Object
- name: Get Object after Put (1) - '{{ test_key }}'
request:
method: POST
url: /getObject
body: '{"key": "key"}'
body: '{"key": "{{ test_key }}"}'
headers:
Content-Type: 'application/json'
Authorization: Bearer eyJhbGciOiJFUzI1NksiLCJraWQiOiIwMzU0N2Q5MmI2MTg4NTZmNGVkYTg0YTY0ZWMzMmYxNjk0Yzk2MDhhM2Y5ZGM3M2U5MWYwOGI1ZGFhMDg3MjYwMTYifQ.eyJleHAiOjE2OTU0NTc4MjgsIm5iZiI6MTY5NTQ1MDYyOCwiaWF0IjoxNjk1NDU0MjI4LCJzdWIiOiIwMjlhOGYwY2MxZWNmZDU5NWNjNzQyYWU5OGU4NDZlNDRjODdmMWJjYWVjNzcxOTZhOTc3MzFjNzllMmJmZDI1ODUifQ.llJlMub-FWU9tgmQRMchziyg6jLGOgKYPq5DOm4dOGUqMCtDyRQX--ILBLhgkHTVhTy0EFyYu0x4clVcb7kV0A
Authorization: Bearer {{ AUTH_TOKEN }}
assign: get_object_response

# Basic assertion to make sure we got a good response with the right key
- name: Extract key from response - '{{ test_key }}'
exec:
command: "echo '{{ get_object_response.body }}' | jq '.key'"
assign: retrieved_key

- name: Compare test_key and retrieved_key - '{{ test_key }}'
exec:
command: "if [ \"{{ test_key }}\" = \"{{ retrieved_key }}\" ]; then echo 'true'; else echo 'false'; fi"
assign: key_comparison_result

- name: Assert keys match - '{{ test_key }}'
assert:
key: key_comparison_result
value: "true"

# Compare the version from "Get Object response" with the assigned version
- name: Compare versions with external command (1) - '{{ test_key }}'
exec:
command: "echo '{{ get_object_response.body }}' | jq --arg version '{{ version }}' '.version == ($version | tonumber)'"
assign: version_match_result

# Assert that the result from the comparison is true
- name: Assert versions match (1) - '{{ test_key }}'
assert:
key: version_match_result
value: "true"

#
## Do this a 2nd time with a bigger version
#
- name: Extract and increment version (2) - '{{ test_key }}'
exec:
command: "echo $(({{ version }} + 1))"
assign: version

- name: Put Objects (2) - '{{ test_key }}'
request:
method: PUT
url: /putObjects
body: '{"transaction_items": [{"key": "{{ test_key }}", "value": [0, 1, 2], "version": {{ version }} }]}'
headers:
Content-Type: 'application/json'
Authorization: Bearer {{ AUTH_TOKEN }}

- name: Get Object after Put (2) - '{{ test_key }}'
request:
method: POST
url: /getObject
body: '{"key": "{{ test_key }}"}'
headers:
Content-Type: 'application/json'
Authorization: Bearer {{ AUTH_TOKEN }}
assign: get_object_response

# Compare the version from "Get Object response" with the assigned version
- name: Compare versions with external command (2) - '{{ test_key }}'
exec:
command: "echo '{{ get_object_response.body }}' | jq --arg version '{{ version }}' '.version == ($version | tonumber)'"
assign: version_match_result

# Basic assertion to make sure we got a good response with the right key
- name: Extract key from response - '{{ test_key }}'
exec:
command: "echo '{{ get_object_response.body }}' | jq '.key'"
assign: retrieved_key

- name: Compare test_key and retrieved_key - '{{ test_key }}'
exec:
command: "if [ \"{{ test_key }}\" = \"{{ retrieved_key }}\" ]; then echo 'true'; else echo 'false'; fi"
assign: key_comparison_result

- name: Assert keys match - '{{ test_key }}'
assert:
key: key_comparison_result
value: "true"

# Assert that the result from the comparison is true
- name: Assert versions match (2) - '{{ test_key }}'
assert:
key: version_match_result
value: "true"

#
## Do this a third time with a bigger version
#
- name: Extract and increment version (3) - '{{ test_key }}'
exec:
command: "echo $(({{ version }} + 1))"
assign: version

- name: Put Objects (3) - '{{ test_key }}'
request:
method: PUT
url: /putObjects
body: '{"transaction_items": [{"key": "{{ test_key }}", "value": [0, 1, 2], "version": {{ version }} }]}'
headers:
Content-Type: 'application/json'
Authorization: Bearer {{ AUTH_TOKEN }}

- name: Get Object after Put (3) - '{{ test_key }}'
request:
method: POST
url: /getObject
body: '{"key": "{{ test_key }}"}'
headers:
Content-Type: 'application/json'
Authorization: Bearer {{ AUTH_TOKEN }}
assign: get_object_response

# Basic assertion to make sure we got a good response with the right key
- name: Extract key from response - '{{ test_key }}'
exec:
command: "echo '{{ get_object_response.body }}' | jq '.key'"
assign: retrieved_key

- name: Compare test_key and retrieved_key - '{{ test_key }}'
exec:
command: "if [ \"{{ test_key }}\" = \"{{ retrieved_key }}\" ]; then echo 'true'; else echo 'false'; fi"
assign: key_comparison_result

- name: Assert keys match - '{{ test_key }}'
assert:
key: key_comparison_result
value: "true"

# Compare the version from "Get Object response" with the assigned version
- name: Compare versions with external command (3) - '{{ test_key }}'
exec:
command: "echo '{{ get_object_response.body }}' | jq --arg version '{{ version }}' '.version == ($version | tonumber)'"
assign: version_match_result

# Assert that the result from the comparison is true
- name: Assert versions match (3) - '{{ test_key }}'
assert:
key: version_match_result
value: "true"

0 comments on commit 2451e70

Please sign in to comment.