Skip to content

Commit

Permalink
add-k6-worfflow
Browse files Browse the repository at this point in the history
  • Loading branch information
maurodandrea committed Oct 7, 2024
1 parent fa766c7 commit c73a46a
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/k6.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: K6 Performance Tests
on:
workflow_dispatch:
inputs:
script:
type: choice
default: 'IdP_keys.js'
options:
- IdP_keys.js
- All_IdP.js
logLevel:
description: 'Log level'
required: true
default: 'warning'
type: choice
options:
- warning

jobs:
performance-tests:
runs-on: ubuntu-latest
env:
K6_BROWSER_ENABLED: false

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Setup k6
uses: grafana/setup-k6-action@v1

- name: Run k6 test
uses: grafana/run-k6-action@v1
with:
path: |
./src/${{ inputs.script }}
- name: Upload Report
uses: actions/upload-artifact@v4
with:
name: k6-browser-report-summary
path: TestSummaryReport.html


26 changes: 26 additions & 0 deletions src/All_IdP.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import http from 'k6/http';
import { check, sleep } from 'k6';
import { htmlReport } from "https://raw.githubusercontent.com/benc-uk/k6-reporter/2.4.0/dist/bundle.js";

export let options = {
stages: [
{ duration: '5s', target: 1 }, // Simula 20 utenti per 30 secondi
{ duration: '10s', target: 2 }, // Riduce a 10 utenti per 1 minuto
{ duration: '3s', target: 1 }, // Riduce a 0 utenti in 10 secondi
],
};

export default function () {
let res = http.get('https://dev.oneid.pagopa.it/idps');
check(res, {
'status was 200': (r) => r.status == 200,
'response time was less than 500ms': (r) => r.timings.duration < 5000,
});
sleep(1);
}

export function handleSummary(data) {
return {
'TestSummaryReport.html': htmlReport(data, { debug: true })
};
}
26 changes: 26 additions & 0 deletions src/Idp_keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import http from 'k6/http';
import { check, sleep } from 'k6';
import { htmlReport } from "https://raw.githubusercontent.com/benc-uk/k6-reporter/2.4.0/dist/bundle.js";

export let options = {
stages: [
{ duration: '5s', target: 10 }, // Simula 20 utenti per 30 secondi
{ duration: '10s', target: 20 }, // Riduce a 10 utenti per 1 minuto
{ duration: '3s', target: 10 }, // Riduce a 0 utenti in 10 secondi
],
};

export default function () {
let res = http.get('https://api.is.eng.pagopa.it/idp-keys/spid/latest');
check(res, {
'status was 200': (r) => r.status == 200,
'response time was less than 500ms': (r) => r.timings.duration < 5000,
});
sleep(1);
}

export function handleSummary(data) {
return {
'TestSummaryReport.html': htmlReport(data, { debug: true })
};
}

0 comments on commit c73a46a

Please sign in to comment.