Skip to content

Commit 563c5b3

Browse files
committed
Organized load tests
1 parent 4d86637 commit 563c5b3

File tree

10 files changed

+7856
-1872
lines changed

10 files changed

+7856
-1872
lines changed

package-lock.json

Lines changed: 7601 additions & 1871 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
"w3-css": "^4.1.0"
6363
},
6464
"devDependencies": {
65-
"qunitjs": "^2.4.1"
65+
"node-fetch": "^2.6.7",
66+
"qunitjs": "^2.4.1",
67+
"uuid": "^8.3.2",
68+
"findit": "^2.0.0"
6669
}
6770
}

test/input/analysis.zip

6.29 MB
Binary file not shown.

test/loadtest/analysisdir.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
config:
2+
target: "http://localhost:3001"
3+
http:
4+
timeout: 120
5+
environments:
6+
production:
7+
target: "https://causalpath.org"
8+
staging:
9+
target: "http://35.192.108.199:3001"
10+
local:
11+
target: "http://localhost:3001"
12+
phases:
13+
- duration: 1
14+
arrivalRate: 20
15+
name: Load
16+
processor: "./processor.js"
17+
scenarios:
18+
- flow:
19+
- post:
20+
url: "/api/analysisDir"
21+
beforeRequest: makeAnalysisDirVars
22+
json:
23+
inputFiles: "{{ inputFiles }}"
24+
room: "{{ room }}"

test/loadtest/analysiszip.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
config:
2+
target: "http://localhost:3001"
3+
http:
4+
timeout: 120
5+
environments:
6+
production:
7+
target: "https://causalpath.org"
8+
staging:
9+
target: "http://35.192.108.199:3001"
10+
local:
11+
target: "http://localhost:3001"
12+
phases:
13+
- duration: 1
14+
arrivalRate: 2
15+
name: Load
16+
processor: "./processor.js"
17+
scenarios:
18+
- flow:
19+
- post:
20+
url: "/api/analysisZip"
21+
beforeRequest: makeAnalysisZipVars
22+
json:
23+
fileContent: "{{ fileContent }}"
24+
room: "{{ room }}"

test/loadtest/demofilepaths.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
config:
2+
target: "http://localhost:3001"
3+
http:
4+
timeout: 10
5+
environments:
6+
production:
7+
target: "https://causalpath.org"
8+
staging:
9+
target: "http://35.192.108.199:3001"
10+
local:
11+
target: "http://localhost:3001"
12+
phases:
13+
- duration: 1
14+
arrivalRate: 20
15+
name: Load
16+
scenarios:
17+
- flow:
18+
- post:
19+
url: "/api/calculateDemoFolderFilePaths"

test/loadtest/downloadrequest.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
config:
2+
target: "http://localhost:3001"
3+
http:
4+
timeout: 10
5+
environments:
6+
production:
7+
target: "https://causalpath.org"
8+
staging:
9+
target: "http://35.192.108.199:3001"
10+
local:
11+
target: "http://localhost:3001"
12+
phases:
13+
- duration: 1
14+
arrivalRate: 20
15+
name: Load
16+
processor: "./processor.js"
17+
scenarios:
18+
- flow:
19+
- post:
20+
url: "/api/downloadRequest"
21+
beforeRequest: makeDownloadRequestVars
22+
json:
23+
room: "{{ room }}"

test/loadtest/getjsonatpath.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
config:
2+
target: "http://localhost:3001"
3+
http:
4+
timeout: 10
5+
environments:
6+
production:
7+
target: "https://causalpath.org"
8+
staging:
9+
target: "http://35.192.108.199:3001"
10+
local:
11+
target: "http://localhost:3001"
12+
phases:
13+
- duration: 1
14+
arrivalRate: 20
15+
name: Load
16+
processor: "./processor.js"
17+
scenarios:
18+
- flow:
19+
- post:
20+
url: "/api/getJsonAtPath"
21+
beforeRequest: makeGetJsonAtPathVars
22+
json:
23+
dir: "{{ path }}"

test/loadtest/mainpage.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
config:
2+
target: "http://localhost:3001"
3+
phases:
4+
- duration: 1
5+
arrivalRate: 20
6+
name: Load
7+
environments:
8+
production:
9+
target: "https://causalpath.org"
10+
staging:
11+
target: "http://35.192.108.199:3001"
12+
local:
13+
target: "http://localhost:3001"
14+
scenarios:
15+
- flow:
16+
- get:
17+
url: "/demo"

test/loadtest/processor.js

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
let fs = require('fs');
2+
let { v4: uuid } = require('uuid');
3+
let fetch = require('node-fetch');
4+
let findit = require('findit');
5+
6+
function getRandomInt(max) {
7+
return Math.floor(Math.random() * max);
8+
}
9+
10+
function getAnalysisZipInput() {
11+
let fileContent = fs.readFileSync( '../input/analysis.zip', 'binary' );
12+
return fileContent;
13+
}
14+
15+
let causalityFilePath = '../../public/demo/PNLL-causality-formatted.txt';
16+
let parametersFilePath = '../../public/demo/parameters.txt';
17+
18+
// To be able to make the download request tests we need to have the enough number of analysis results
19+
// first. Since some analysis may end earlier then the others it may cause the some download requests start
20+
// much later earlier then some others. This may make us load testing much smaller number of download requests
21+
// then we would rather.
22+
// Therefore, I want to make sure that we start the all download requests at the time when all of the
23+
// analysis requests are ended. This file will be used to observe if all of the analysis requests are completed.
24+
// I tried a few other ways but none of them was feasible. Therefore, I had to use this workaround.
25+
let countFileName = './download_request_count.txt'
26+
27+
if ( !fs.existsSync(countFileName) ) {
28+
fs.writeFileSync(countFileName, '');
29+
}
30+
31+
function readFile(filePath){
32+
var fileContent = fs.readFileSync(filePath, 'utf-8');
33+
return fileContent;
34+
};
35+
36+
function makeAnalysisDirVars(requestParams, ctx, ee, next) {
37+
let fileNames = [ 'PNLL-causality-formatted.txt', 'parameters.txt' ];
38+
let inputFiles = fileNames.map( name => {
39+
let content = readFile( '../../public/demo/' + name );
40+
return { content, name };
41+
} );
42+
ctx.vars["inputFiles"] = inputFiles;
43+
ctx.vars["room"] = uuid();
44+
45+
return next();
46+
}
47+
48+
function makeGetJsonAtPathVars(requestParams, ctx, ee, next) {
49+
let finder = findit('../../analysisOut');
50+
let paths = [];
51+
finder.on('file', function (file, stat) {
52+
// console.log(file);
53+
if ( file.endsWith('causative.json') ) {
54+
paths.push(file);
55+
}
56+
});
57+
58+
finder.on('end', function () {
59+
// TODO: Handle no path case?
60+
let i = getRandomInt( paths.length - 1 );
61+
ctx.vars["path"] = paths[ i ].replace('../../', './');
62+
console.log(paths[i])
63+
next();
64+
});
65+
}
66+
67+
function makeAnalysisZipVars(requestParams, ctx, ee, next) {
68+
let fileContent = getAnalysisZipInput();
69+
ctx.vars["fileContent"] = fileContent;
70+
ctx.vars["room"] = uuid();
71+
72+
return next();
73+
}
74+
75+
function makeDownloadRequestVars(requestParams, ctx, ee, next){
76+
let interval = 5000;
77+
var intervalID = setInterval( () => {
78+
var fileContent = fs.readFileSync(countFileName);
79+
// the expected length may change based on the number of requests
80+
// TODO: may take the number of requests from the yml file as a parameter?
81+
if ( fileContent.length == 20 ) {
82+
return new Promise(resolve => setTimeout(resolve, interval)).then( () => {
83+
if ( fs.existsSync(countFileName) ) {
84+
fs.unlinkSync(countFileName);
85+
}
86+
clearInterval(intervalID);
87+
next();
88+
} );
89+
}
90+
}, interval );
91+
console.log(uuid)
92+
let room = uuid();
93+
ctx.vars["room"] = room;
94+
95+
let fileContent = getAnalysisZipInput();
96+
let q = {
97+
fileContent,
98+
room
99+
};
100+
101+
console.log('preparing for download request, called analysisZip for room ', room);
102+
let makeRequest = () => fetch( 'http://localhost:3001/api/analysisZip', {
103+
method: 'POST',
104+
headers: {
105+
'content-type': 'application/json'
106+
},
107+
body: JSON.stringify(q)
108+
});
109+
110+
makeRequest().then( () => {
111+
console.log('analysis is done for room ', room);
112+
fs.appendFileSync(countFileName, '1');
113+
} );
114+
}
115+
116+
module.exports = {
117+
makeAnalysisDirVars,
118+
makeAnalysisZipVars,
119+
makeDownloadRequestVars,
120+
makeGetJsonAtPathVars
121+
};

0 commit comments

Comments
 (0)