diff --git a/.github/workflows/load_test.yml b/.github/workflows/load_test.yml index 57775c1..4e07c5b 100644 --- a/.github/workflows/load_test.yml +++ b/.github/workflows/load_test.yml @@ -2,8 +2,8 @@ name: Hub Load Test on: push: - branches: - - add-workflow + # branches: + # - add-workflow workflow_dispatch: inputs: @@ -15,16 +15,21 @@ on: options: - GET - POST + - POST_WITH_FILES host: description: 'Target host' required: true default: 'https://api.simplehash.com' + type: choice + options: + - https://api.simplehash.com + - https://edge.stg.storyprotocol.net number-of-users: - description: 'Peak concurrency' + description: 'Number of users(peak concurrency)' required: true default: '100' ramp-up: - description: 'users started/second' + description: 'Ramp up (users started/second)' required: true default: '2' run_time: @@ -70,6 +75,13 @@ jobs: 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 ./test_report/load-test-report_${{ steps.set_timestamp.outputs.timestamp }}.html continue-on-error: true + - name: Run Locust + if: ${{ github.event.inputs.requst-methold == 'POST_WITH_FILES' }} + run: | + rm -rf ./test_report/* + locust -f src/test_scripts/test_upload_image.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 ./test_report/load-test-report_${{ steps.set_timestamp.outputs.timestamp }}.html + continue-on-error: true + - name: Deploy report to GitHub Pages if: always() uses: peaceiris/actions-gh-pages@v4 diff --git a/src/test_scripts/test_upload_image.py b/src/test_scripts/test_upload_image.py new file mode 100644 index 0000000..abcc3f9 --- /dev/null +++ b/src/test_scripts/test_upload_image.py @@ -0,0 +1,20 @@ +from locust import HttpUser, task, between +from src.utils.api import send_post_request, send_get_request, send_post_request_with_files +from src.utils.common import get_config + +bearer_token = "Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjAyMmZhMzE4LTU4OGItNGVjMi05ZjEzLWNlMDA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N4BCk-0Y1qAGlixVVNrQxu0n6MTp0MKmuXaN5_9DFOqvjKlNCR5Y6Z7hPY" + +class UserBehavior(HttpUser): + wait_time = between(1, 10) + + @task + def post_api(self): + # env_config = get_config('config.json') + path = "https://edge.stg.storyprotocol.net/hub/users/v1/upload" + headers = { + 'Authorization': bearer_token + } + payload = {'file_name': 'test_image.png'} + files=[('file',('test_image.png',open('test_image.png','rb'),'image/png'))] + + send_post_request_with_files(self, path, headers, payload, files) diff --git a/src/utils/api.py b/src/utils/api.py index 0e3e65d..1ff9f21 100644 --- a/src/utils/api.py +++ b/src/utils/api.py @@ -3,6 +3,7 @@ def send_get_request(self, path, headers): response = self.client.get(path, headers=headers) if response.status_code != 200: print(f"API call failed with status code: {response.status_code}") + print(f"POST request failed with status code: {response.text}") def send_post_request(self, path, headers, payload): @@ -10,3 +11,11 @@ def send_post_request(self, path, headers, payload): if response.status_code != 200: print(f"POST request failed with status code: {response.status_code}") + print(f"POST request failed with status code: {response.text}") + +def send_post_request_with_files(self, path, headers, payload, files): + response = self.client.post(path, headers=headers, json=payload, files=files) + + if response.status_code != 200: + print(f"POST request failed with status code: {response.status_code}") + print(f"POST request failed with status code: {response.text}") diff --git a/test_image.png b/test_image.png new file mode 100644 index 0000000..28883a8 Binary files /dev/null and b/test_image.png differ