Skip to content

Commit

Permalink
add workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jacqueline-57b committed Sep 24, 2024
1 parent cbe0ad6 commit fcdebdc
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
62 changes: 59 additions & 3 deletions .github/workflows/load_test.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
# .github/workflows/locust.yml
name: Locust Performance Test
name: Hub Load Test

on:
push:
branches:
- add-workflow

workflow_dispatch:
inputs:
requst-methold:
description: 'Select request method'
required: true
default: 'GET'
type: choice
options:
- GET
- POST
host:
description: 'Target host'
required: true
default: 'https://api.simplehash.com'
number-of-users:
description: 'Peak concurrency'
required: true
default: '100'
ramp-up:
description: 'users started/second'
required: true
default: '2'
run_time:
description: 'Run time (e.g. 20, 20s, 3m, 2h, etc.)'
required: true
default: '10m'

jobs:
locust:
runs-on: ubuntu-latest
Expand All @@ -23,6 +49,36 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Set Timestamp
id: set_timestamp
run: |
TIMESTAMP=$(date +'%Y%m%d_%H%M%S')
echo "timestamp=$TIMESTAMP" >> $GITHUB_ENV
- name: Run Locust
if: ${{ github.event.inputs.requst-methold == 'GET' }}
run:
locust -f src/test_scripts/test_get_api.py --headless -u ${{ github.event.inputs.number-of-users }} -r ${{ github.event.inputs.ramp-up }} --run-time ${{ github.event.inputs.run_time }} --host ${{ github.event.inputs.host }} --html "load-test-report_$timestamp.html"

- name: Run Locust
run: locust -f src/test_scripts/test_get_api.py --headless -u 1000 -r 10 --run-time 20m --host https://api.simplehash.com
if: ${{ github.event.inputs.requst-methold == 'POST' }}
run: |
locust -f src/test_scripts/test_post_api.py --headless -u ${{ github.event.inputs.number-of-users }} -r ${{ github.event.inputs.ramp-up }} --run-time ${{ github.event.inputs.run_time }} --host ${{ github.event.inputs.host }} --html "load-test-report_$timestamp.html"
- name: Deploy report to GitHub Pages
if: always()
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./load-test-report_$timestamp.html
publish_branch: gh-pages
keep_files: true

- name: Upload Test Report
if: always()
uses: actions/upload-artifact@v4
with:
name: hub-load-test-report
path: |
./load-test-report_$timestamp.html
8 changes: 2 additions & 6 deletions src/utils/api.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@

def send_get_request(self, path, headers):
response = self.client.get(path, headers=headers)
if response.status_code == 200:
print("API call successful")
else:
if response.status_code != 200:
print(f"API call failed with status code: {response.status_code}")


def send_post_request(self, path, headers, payload):
response = self.client.post(path, headers=headers, json=payload)

if response.status_code == 200:
print("POST request successful")
else:
if response.status_code != 200:
print(f"POST request failed with status code: {response.status_code}")

0 comments on commit fcdebdc

Please sign in to comment.