Skip to content

Commit 8cad6dd

Browse files
NRL-1666 Fix broken NHS number generation & document how to run perf tests. SUccessfully ran producer tests
1 parent e7d3408 commit 8cad6dd

File tree

3 files changed

+47
-33
lines changed

3 files changed

+47
-33
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ APP_ALIAS ?= default
1616
HOST ?= $(TF_WORKSPACE_NAME).api.record-locator.$(ENV).national.nhs.uk
1717
ENV_TYPE ?= $(ENV)
1818
PERFTEST_TABLE_NAME ?= perftest
19-
PERFTEST_HOST ?= api.perftest.record-locator.national.nhs.uk
19+
PERFTEST_HOST ?= perftest-1.perftest.record-locator.national.nhs.uk
2020

2121
export PATH := $(PATH):$(PWD)/.venv/bin
2222
export USE_SHARED_RESOURCES := $(shell poetry run python scripts/are_resources_shared_for_stack.py $(TF_WORKSPACE_NAME))

tests/performance/README.md

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,48 @@ some high level context short
66

77
## Run perf tests
88

9+
### Prep the environment
10+
11+
Perf tests are generally conducted in the perftest env. There's a selection of tables in the perftest env representing different pointer volume scenarios e.g. perftest-baseline vs perftest-1million (todo: update with real names!).
12+
13+
To reset this table to the expected state for perftests, restore the table from a backup.
14+
15+
In the steps below, make sure the table name is the table your environment is pointing at. You might need to redeploy NRLF lambdas to point at the desired table.
16+
17+
### Prepare to run tests
18+
19+
#### Pull certs for env
20+
921
```sh
1022
assume management
11-
make truststore-pull-all ENV=<env> # e.g. perftest
23+
make truststore-pull-all ENV=perftest
24+
```
25+
26+
#### Generate permissions
27+
28+
You will need to generate pointer permissions the first time performance tests are run in an environment e.g. if the perftest environment is destroyed & recreated.
29+
30+
```sh
31+
make generate permissions # makes a bunch of json permission files
32+
make build # will take all permissions & create nrlf_permissions.zip file
33+
34+
# apply this new permissions zip file to your environment
1235
cd ./terraform/infrastructure
13-
tf workspace select # perftest-1 or active stack
14-
cd ../../ # project root
15-
assume
16-
make perftest-prepare PERFTEST_TABLE_NAME=<pointer table name>
36+
assume test # needed?
37+
make init TF_WORKSPACE_NAME=perftest-1 ENV=perftest
38+
tf apply
39+
```
40+
41+
#### Generate input files
1742

18-
make perftest-consumer ENV_TYPE=<env> # e.g. perftest
43+
```sh
44+
# creates 2 csv files and a json file
45+
make perftest-prepare PERFTEST_TABLE_NAME=perftest-baseline
1946
```
2047

21-
<!-- Mention relevant input files + any environment prep needed e.g. restoring tables from backup -->
48+
### Run tests
49+
50+
```sh
51+
make perftest-consumer ENV_TYPE=perftest PERFTEST_HOST=perftest-1.perftest.record-locator.national.nhs.uk
52+
make perftest-producer ENV_TYPE=perftest PERFTEST_HOST=perftest-1.perftest.record-locator.national.nhs.uk
53+
```

tests/performance/producer/client_perftest.js

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -58,51 +58,33 @@ function generateValidNHSNumber(start, end) {
5858

5959
while (!nhsNumber) {
6060
const seedNumber = randomNHSNumberInRange(start, end);
61-
const first9Str = String(seedNumber).padStart(9, "0").substring(0, 8);
61+
const first9Str = String(seedNumber).padStart(9, "0").substring(0, 9);
6262

63-
console.log(
64-
`Generating NHS number from seed: ${seedNumber}, first 9 digits: ${first9Str}`
65-
);
66-
67-
if (first9Str.match(/^\d{9}$/)) {
63+
if (!first9Str.match(/^\d{9}$/)) {
6864
throw new Error(
6965
`bad NHS number generated - expected 9 digits: ${first9Str}, ${seedNumber}`
7066
);
7167
}
7268

73-
//parts_list = [
74-
// int(digit) * (10 - index)
75-
// for index, digit in enumerate(identifier_digits)
76-
//]
77-
//list_sum = sum(parts_list)
78-
//checksum = 11 - (list_sum % 11)
79-
//if checksum == 11:
80-
// checksum = 0
81-
//return checksum
82-
8369
const parts = [];
8470
const digits = first9Str.split("");
8571
for (let i = 0; i < digits.length; i++) {
8672
parts.push(parseInt(digits[i], 10) * (10 - i));
8773
}
88-
8974
const list_sum = parts.reduce((a, b) => a + b, 0);
90-
let checksum = 11 - (list_sum % 11);
91-
if (checksum === 11) {
92-
checksum = 0;
93-
}
9475

95-
console.log(
96-
`Generated NHS number parts: ${parts}, sum: ${list_sum}, checksum: ${checksum}`
97-
);
76+
let checksum = 11 - (list_sum % 11);
9877

9978
if (checksum === 10) {
10079
// Checksum of 10 means NHS number is invalid
10180
continue;
10281
}
10382

83+
if (checksum === 11) {
84+
checksum = 0;
85+
}
86+
10487
nhsNumber = `${first9Str}${checksum}`;
105-
console.log(`Generated NHS number: ${nhsNumber}`);
10688
}
10789

10890
return nhsNumber;

0 commit comments

Comments
 (0)