Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respond to tony's updates #3

Merged
merged 7 commits into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ edition = "2021"
[dependencies]
anyhow = "1.0"
axum = { version = "0.6.16", features = ["headers"] }
base64 = "0.13.1"
chrono = { version = "0.4.26", features = ["serde"] }
diesel = { version = "2.1", features = ["postgres", "r2d2", "chrono", "numeric"] }
diesel_migrations = "2.1.0"
dotenv = "0.15.0"
futures = "0.3.28"
hex = "0.4.3"
Expand All @@ -23,3 +23,6 @@ tokio = { version = "1.12.0", features = ["full"] }
tower-http = { version = "0.4.0", features = ["cors"] }

ureq = { version = "2.5.0", features = ["json"] }

[dev-dependencies]
diesel_migrations = "2.1.0"
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
```
188 changes: 188 additions & 0 deletions drill.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
base: 'https://vss-staging.fly.dev'
concurrency: 125
iterations: 2000

plan:
- name: Health Check
request:
method: GET
url: /health-check

# 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": "{{ test_key }}", "value": [0, 1, 2], "version": {{ version }} }]}'
headers:
Content-Type: 'application/json'
Authorization: Bearer {{ AUTH_TOKEN }}

- name: Get Object after Put (1) - '{{ 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 (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"
43 changes: 0 additions & 43 deletions migrations/2023-09-18-225828_baseline/up.sql

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions migrations/2023-09-20-043550_change-default-timestamp/up.sql

This file was deleted.

Loading
Loading