-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add k6 API testing (smoke+stress)
- Loading branch information
1 parent
a969265
commit 7321c07
Showing
6 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Run k6 API testsuite | ||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
run-test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup K6 | ||
uses: grafana/setup-k6-action@v1 | ||
|
||
- name: Run local k6 / API Smoke testing | ||
uses: grafana/run-k6-action@v1 | ||
env: | ||
K6_CLOUD_TOKEN: ${{ secrets.K6_CLOUD_TOKEN }} | ||
K6_CLOUD_PROJECT_ID: ${{ secrets.K6_CLOUD_PROJECT_ID }} | ||
AUTH_TOKEN: ${{ secrets.ADMIN_AUTH_TOKEN }} | ||
with: | ||
path: k6/api-smoke.js | ||
|
||
- name: Run local k6 / API Stress testing | ||
uses: grafana/run-k6-action@v1 | ||
env: | ||
K6_CLOUD_TOKEN: ${{ secrets.K6_CLOUD_TOKEN }} | ||
K6_CLOUD_PROJECT_ID: ${{ secrets.K6_CLOUD_PROJECT_ID }} | ||
AUTH_TOKEN: ${{ secrets.ADMIN_AUTH_TOKEN }} | ||
with: | ||
path: k6/api-stress.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import http from 'k6/http'; | ||
import { check, sleep } from 'k6'; | ||
|
||
const paths = [ | ||
'/articles', | ||
'/features', | ||
'/projects', | ||
'/articles/@id', | ||
'/articles/@id/comments', | ||
'/articles/@id/recommendations', | ||
]; | ||
|
||
export default function () { | ||
for (let path of paths) { | ||
const res = http.get( | ||
`https://api.udfn.fr${path.replace('@id', 'NMVntUf1yiwhMkrOftLNB')}`, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${__ENV.AUTH_TOKEN}` | ||
} | ||
} | ||
); | ||
check(res, { | ||
'is status 200': (r) => r.status === 200, | ||
}); | ||
|
||
sleep(0.1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import http from 'k6/http'; | ||
import { check } from 'k6'; | ||
import { randomItem } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js'; | ||
|
||
const paths = [ | ||
'/articles', | ||
'/features', | ||
'/projects', | ||
'/articles/@id', | ||
'/articles/@id/comments', | ||
'/articles/@id/recommendations', | ||
]; | ||
|
||
const articles = [ | ||
'NMVntUf1yiwhMkrOftLNB', | ||
'4aAkSjsn311n0jwAgNnIvH', | ||
'7rLwY85ICqoRIXKyHeeSGY', | ||
'1UXgm0ZL7D1rysOnysYlrM', | ||
'1yN0AOunIiaLn8nXZc7k6z', | ||
'4EXN4ffKnY92zPpVS1xrVn', | ||
'6J0hWoFCuiuWQtjp3K1mXn', | ||
]; | ||
|
||
export const options = { | ||
vus: 50, | ||
duration: '1m', | ||
}; | ||
|
||
export default function () { | ||
const path = randomItem(paths).replace('@id', randomItem(articles)); | ||
const res = http.get( | ||
`https://api.udfn.fr${path}`, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${__ENV.AUTH_TOKEN}` | ||
} | ||
} | ||
); | ||
check(res, { | ||
'is status 200': (r) => r.status === 200, | ||
}); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"dependencies": { | ||
"@types/k6": "^0.54.1", | ||
"k6": "^0.0.0" | ||
} | ||
} |