Skip to content

Commit 8aa8cce

Browse files
committed
Have two scenarios, one for allowed ODS codes, one for blocked ones
1 parent 13c7d46 commit 8aa8cce

3 files changed

Lines changed: 57 additions & 46 deletions

File tree

artillery/helper/odscodes.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ export const allowedOdsCodes = [
44
]
55

66
export const blockedOdsCodes = [
7-
// "B3J1Z"
8-
]
7+
"B3J1Z"
8+
]

artillery/notify_entrypoint.mjs

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,6 @@ export { getSharedAuthToken }
77

88
const logger = pino()
99

10-
const LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
11-
const DIGITS = "0123456789";
12-
13-
const randomChar = (chars) => chars[Math.floor(Math.random() * chars.length)];
14-
15-
/** Generate one two-letter, three-digit ODS code, e.g. "AB123" */
16-
const generateOdsCode = () =>
17-
`${randomChar(LETTERS)}${randomChar(LETTERS)}${randomChar(DIGITS)}${randomChar(DIGITS)}${randomChar(DIGITS)}`;
18-
19-
function buildFullOdsCodes(targetCount, seedCodes) {
20-
const codes = new Set(seedCodes);
21-
22-
while (codes.size < targetCount) {
23-
codes.add(generateOdsCode());
24-
}
25-
26-
return Array.from(codes);
27-
}
28-
29-
// The complete list of ODS codes
30-
const fullOdsCodes = allowedOdsCodes.concat(blockedOdsCodes)
31-
3210
function computeCheckDigit(nhsNumber) {
3311
const factors = [10,9,8,7,6,5,4,3,2]
3412
let total = 0
@@ -62,23 +40,42 @@ function sampleNormal(mean = 0, sd = 1) {
6240
return z * sd + mean;
6341
}
6442

65-
export function initUser(context, events, done) {
66-
// Generate data for a patient
67-
context.vars.odsCode = fullOdsCodes[Math.floor(Math.random()*fullOdsCodes.length)]
68-
context.vars.nhsNumber = generateValidNhsNumber()
43+
function initUserContextVars(context) {
44+
context.vars.nhsNumber = generateValidNhsNumber()
6945

70-
let prescriptionCount = Math.round(sampleNormal(3,1))
71-
if (prescriptionCount < 1) prescriptionCount = 1 // just truncate at 1.
72-
context.vars.prescriptionCount = prescriptionCount
73-
context.vars.loopcount = 0
74-
75-
logger.info(`Patient ${context.vars.nhsNumber}, ODS ${context.vars.odsCode} has ${context.vars.prescriptionCount} prescriptions`)
76-
77-
done()
46+
let prescriptionCount = Math.round(sampleNormal(3,1))
47+
if (prescriptionCount < 1) prescriptionCount = 1 // just truncate at 1.
48+
context.vars.prescriptionCount = prescriptionCount
49+
context.vars.loopcount = 0
50+
}
51+
52+
export function initUserAllowed(context, events, done) {
53+
logger.info("Initializing user context variables for allowed ODS codes")
54+
initUserContextVars(context)
55+
56+
// Generate data for a patient with an allowed ODS code
57+
context.vars.odsCode = allowedOdsCodes[Math.floor(Math.random() * allowedOdsCodes.length)]
58+
59+
logger.info(`[ALLOWED] Patient ${context.vars.nhsNumber}, ODS ${context.vars.odsCode} has ${context.vars.prescriptionCount} prescriptions`)
60+
done()
61+
}
62+
63+
export function initUserBlocked(context, events, done) {
64+
logger.info("Initializing user context variables for allowed ODS codes")
65+
initUserContextVars(context)
66+
67+
// Generate data for a patient with a blocked ODS code
68+
context.vars.odsCode = blockedOdsCodes[Math.floor(Math.random() * blockedOdsCodes.length)]
69+
70+
logger.info(`[BLOCKED] Patient ${context.vars.nhsNumber}, ODS ${context.vars.odsCode} has ${context.vars.prescriptionCount} prescriptions`)
71+
done()
7872
}
7973

8074
export function generatePrescData(requestParams, context, ee, next) {
81-
logger.debug(`Generating a prescription for patient ${context.vars.nhsNumber}`)
75+
const isAllowed = allowedOdsCodes.includes(context.vars.odsCode);
76+
const logPrefix = isAllowed ? "[ALLOWED]" : "[BLOCKED]";
77+
78+
logger.debug(`${logPrefix} Generating a prescription for patient ${context.vars.nhsNumber}`)
8279
const body = getBody(
8380
true, /* isValid */
8481
"completed", /* status */
@@ -87,11 +84,11 @@ export function generatePrescData(requestParams, context, ee, next) {
8784
"ready to collect" /* Item status */
8885
)
8986
// The body is fine - it works when I put it in postman
90-
87+
9188
requestParams.json = body
9289
context.vars.x_request_id = uuidv4()
9390
context.vars.x_correlation_id = uuidv4()
94-
91+
9592
context.vars.loopcount += 1
9693

9794
// Wait this long between requests
@@ -104,8 +101,6 @@ export function generatePrescData(requestParams, context, ee, next) {
104101
}
105102

106103
context.vars.nextDelay = delay
107-
logger.debug(`Patient ${context.vars.nhsNumber} (on prescription update ${context.vars.loopcount}/${context.vars.prescriptionCount}) will think for ${context.vars.nextDelay} seconds`)
108-
104+
logger.debug(`${logPrefix} Patient ${context.vars.nhsNumber} (on prescription update ${context.vars.loopcount}/${context.vars.prescriptionCount}) will think for ${context.vars.nextDelay} seconds`)
109105
next()
110106
}
111-

artillery/notify_load_test.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,28 @@ before:
2828
- function: getSharedAuthToken
2929

3030
scenarios:
31-
- name: dynamic PSU calls for each patient
32-
31+
- name: Allowed ODS code scenario
32+
weight: 1
3333
flow:
34-
- function: initUser
34+
- function: initUserAllowed
35+
- loop:
36+
- function: getSharedAuthToken
37+
- post:
38+
url: "/prescription-status-update/"
39+
beforeRequest: "generatePrescData"
40+
headers:
41+
Authorization: "Bearer {{ authToken }}"
42+
x-request-id: "{{ x_request_id }}"
43+
x-correlation-id: "{{ x_correlation_id }}"
44+
expect:
45+
- statusCode: 201
46+
- think: "{{ nextDelay }}seconds"
47+
count: "{{ prescriptionCount }}"
3548

36-
# for each prescription (number of prescriptions is variable)
49+
- name: Blocked ODS code scenario
50+
weight: 3
51+
flow:
52+
- function: initUserBlocked
3753
- loop:
3854
- function: getSharedAuthToken
3955
- post:

0 commit comments

Comments
 (0)