Skip to content

Commit ef157f2

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

File tree

3 files changed

+47
-35
lines changed

3 files changed

+47
-35
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 & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,51 @@
11
# Performance Testing
22

3-
<!-- TODO: make this proper -->
4-
53
some high level context short
64

75
## Run perf tests
86

7+
### Prep the environment
8+
9+
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!).
10+
11+
To reset this table to the expected state for perftests, restore the table from a backup.
12+
13+
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.
14+
15+
### Prepare to run tests
16+
17+
#### Pull certs for env
18+
919
```sh
1020
assume management
11-
make truststore-pull-all ENV=<env> # e.g. perftest
21+
make truststore-pull-all ENV=perftest
22+
```
23+
24+
#### Generate permissions
25+
26+
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.
27+
28+
```sh
29+
make generate permissions # makes a bunch of json permission files
30+
make build # will take all permissions & create nrlf_permissions.zip file
31+
32+
# apply this new permissions zip file to your environment
1233
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>
34+
assume test # needed?
35+
make init TF_WORKSPACE_NAME=perftest-1 ENV=perftest
36+
tf apply
37+
```
38+
39+
#### Generate input files
1740

18-
make perftest-consumer ENV_TYPE=<env> # e.g. perftest
41+
```sh
42+
# creates 2 csv files and a json file
43+
make perftest-prepare PERFTEST_TABLE_NAME=perftest-baseline
1944
```
2045

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

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)