-
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.
PHAIN-123: Add PHA import notifications updates performance tests (#6)
- Loading branch information
Showing
14 changed files
with
241 additions
and
40 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
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
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
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
This file was deleted.
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,16 @@ | ||
const config = { | ||
low: { | ||
http_req_duration: ['p(90)<2500'], | ||
http_req_failed: ['rate<0.01'], | ||
}, | ||
medium: { | ||
http_req_duration: ['p(90)<400', 'p(95)<800', 'p(99.9)<2000'], | ||
http_req_failed: ['rate<0.01'], | ||
}, | ||
high: { | ||
http_req_duration: ['p(90)<250', 'p(95)<500', 'p(99.9)<1500'], | ||
http_req_failed: ['rate<0.01'], | ||
}, | ||
}; | ||
|
||
export const threshold = config[__ENV.K6_THRESHOLD] || config['low']; |
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,34 @@ | ||
const config = { | ||
// 12 iterations of the user journey over 15 mins (average volume of traffic) | ||
load: { | ||
executor: 'constant-arrival-rate', | ||
duration: '15m', | ||
preAllocatedVUs: 1, | ||
rate: 12, | ||
timeUnit: '15m', | ||
}, | ||
// 1200 iterations of the user journey over 15 mins (100x average volume of traffic) | ||
stress: { | ||
executor: 'constant-arrival-rate', | ||
duration: '15m', | ||
preAllocatedVUs: 12, | ||
rate: 1200, | ||
timeUnit: '15m', | ||
}, | ||
// Ramp up to 300 virtual users in 1 min with each virtual user completing as many iterations of the user journey as possible | ||
spike: { | ||
executor: 'ramping-vus', | ||
stages: [ | ||
{duration: '1m', target: 300}, | ||
{duration: '30s', target: 0}, | ||
], | ||
}, | ||
// 1 iteration of the user journey for validation purposes | ||
smoke: { | ||
executor: 'per-vu-iterations', | ||
vus: 1, | ||
iterations: 1, | ||
}, | ||
}; | ||
|
||
export const workload = config[__ENV.K6_WORKLOAD] || config['smoke']; |
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,24 @@ | ||
{ | ||
"importNotifications": [ | ||
{ | ||
"scenario": "Example CHED-A.", | ||
"referenceNumber": "CHEDA.GB.2024.4792831" | ||
}, | ||
{ | ||
"scenario": "Example CHED-D with linked movements.", | ||
"referenceNumber": "CHEDD.GB.2024.5019877" | ||
}, | ||
{ | ||
"scenario": "Example CHED-P.", | ||
"referenceNumber": "CHEDP.GB.2024.4144842" | ||
}, | ||
{ | ||
"scenario": "Example CHED-PP.", | ||
"referenceNumber": "CHEDPP.GB.2024.3726460" | ||
}, | ||
{ | ||
"scenario": "Example CHED-A with linked movements.", | ||
"referenceNumber": "CHEDA.GB.2024.5129502" | ||
} | ||
] | ||
} |
File renamed without changes.
Large diffs are not rendered by default.
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,34 @@ | ||
import http from 'k6/http'; | ||
import {URLSearchParams} from '../libs/k6-url-1.0.0.js'; | ||
|
||
const targetUrl = `${__ENV.K6_TARGET_URL}/import-notifications`; | ||
|
||
export function getUpdates(accessToken, bcp, from, to) { | ||
const searchParams = new URLSearchParams([ | ||
['bcp', bcp], | ||
['from', from], | ||
['to', to], | ||
]); | ||
|
||
const url = `${targetUrl}?${searchParams.toString()}`; | ||
|
||
const params = { | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
}; | ||
|
||
return http.get(url, params); | ||
} | ||
|
||
export function getImportNotification(accessToken, referenceNumber) { | ||
const url = `${targetUrl}/${referenceNumber}`; | ||
|
||
const params = { | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
}; | ||
|
||
return http.get(url, params); | ||
} |
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,30 @@ | ||
import {check} from 'k6'; | ||
import encoding from 'k6/encoding'; | ||
import http from 'k6/http'; | ||
|
||
export function getAccessToken(tokenUrl, clientId, clientSecret) { | ||
const url = `${tokenUrl}/oauth2/token`; | ||
|
||
const body = { | ||
grant_type: 'client_credentials', | ||
client_id: clientId, | ||
client_secret: clientSecret, | ||
}; | ||
|
||
const encodedCredentials = encoding.b64encode(`${clientId}:${clientSecret}`); | ||
|
||
const params = { | ||
headers: { | ||
Authorization: `Basic ${encodedCredentials}`, | ||
}, | ||
}; | ||
|
||
const response = http.post(url, body, params); | ||
|
||
check(response, { | ||
'is status 200': (r) => r.status === 200, | ||
'has access token': (r) => r.json().hasOwnProperty('access_token'), | ||
}); | ||
|
||
return response.json().access_token; | ||
} |
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,66 @@ | ||
import {check, group} from 'k6'; | ||
import {SharedArray} from 'k6/data'; | ||
import {threshold} from '../config/thresholds.js'; | ||
import {workload} from '../config/workloads.js'; | ||
import {htmlReport} from '../libs/k6-reporter-2.3.0.js'; | ||
import * as service from '../requests/import-notifications.js'; | ||
import * as oauth from '../requests/oauth.js'; | ||
|
||
export const options = { | ||
scenarios: { | ||
workload, | ||
}, | ||
thresholds: threshold, | ||
}; | ||
|
||
const testData = new SharedArray('import notifications', function () { | ||
return JSON.parse( | ||
open('../data/import-notifications.json') | ||
).importNotifications; | ||
}); | ||
|
||
export function setup() { | ||
const tokenUrl = __ENV.TEST_CLIENT_LOGIN_URL; | ||
const clientId = __ENV.TEST_CLIENT_APP_ID; | ||
const clientSecret = __ENV.TEST_CLIENT_SECRET; | ||
|
||
return oauth.getAccessToken(tokenUrl, clientId, clientSecret); | ||
} | ||
|
||
export default function (accessToken) { | ||
group('PHA import notifications updates', function () { | ||
const bcp = 'GBTEEP1'; | ||
const from = '2025-01-07T10:21:28.3970000Z'; | ||
const to = '2025-01-07T10:21:38.3970000Z'; | ||
|
||
const response = service.getUpdates(accessToken, bcp, from, to); | ||
|
||
check(response, { | ||
'is status 200': (r) => r.status === 200, | ||
'has import notifications': (r) => | ||
r.json().hasOwnProperty('importNotifications'), | ||
}); | ||
|
||
// TODO: Remove loop when test data is updated, results in 15 requests, the target (average) is 13.175859517 | ||
for (let i = 0; i < 3; i++) { | ||
for (const importNotification of testData) { | ||
const response = service.getImportNotification( | ||
accessToken, | ||
importNotification.referenceNumber | ||
); | ||
|
||
check(response, { | ||
'is status 200': (r) => r.status === 200, | ||
'verify reference number': (r) => | ||
r.json().referenceNumber === importNotification.referenceNumber, | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
export function handleSummary(data) { | ||
return { | ||
'index.html': htmlReport(data), | ||
}; | ||
} |