Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 2785782

Browse files
author
Alex
authored
Stress Tests 3 - create long duration ws tests (#6588)
* add script * add eslint disable * add details * add browser test * fix manual ws test cases * add manual tests to stress folder * update naming * add test:manual script * rename folder * update script * add html comment
1 parent af91519 commit 2785782

File tree

4 files changed

+167
-0
lines changed

4 files changed

+167
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ yarn add web3
8686
| test | Uses `jest` to run unit tests in each package |
8787
| test:integration | Uses `jest` to run tests under `/test/integration` in each package |
8888
| test:unit | Uses `jest` to run tests under `/test/unit` in each package |
89+
| test:manual | Runs manual tests under `test/manual` in the web3 package |
8990

9091
[npm-url]: https://npmjs.org/package/web3
9192
[downloads-image]: https://img.shields.io/npm/dm/web3?label=npm%20downloads

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@
8888
"test:manual:stress:data": "packages/web3/test/stress/start.sh",
8989
"test:manual:stress:validation": "npx ts-node packages/web3/test/stress/validator.ts",
9090
"test:manual:stress": "yarn test:manual:stress:data && yarn test:manual:stress:validation",
91+
"test:manual:long-connection-ws":"node ./packages/web3/test/manual/long_ws_tests/nodejs_test/long_connection_ws.js",
92+
"test:manual":"yarn test:manual:stress && yarn test:manual:long-connection-ws",
9193
"husky:install": "husky install",
9294
"husky:uninstall": "husky uninstall",
9395
"postinstall": "yarn build",
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Manual browser tests</title>
7+
<!-- To Run -->
8+
<script src="../../../../dist/web3.min.js">
9+
</script>
10+
</head>
11+
<body>
12+
13+
<p> Manual browser test - for this test you will need to provide an ws infura endpoint in this html page. This will test the web3js ws provider by sending a request every 10 minutes for 10 hours </p>
14+
<p> Have this html test open in a browser of your choice</p>
15+
<p> Keep dev console open in case of any unintended errors occur </p>
16+
<!-- Display start date -->
17+
<p>Start time: <span id="startTime"></span></p>
18+
19+
<!-- Display end date -->
20+
<p>End Time: <span id="endTime"></span></p>
21+
22+
<!-- Display attempts made -->
23+
<p>Number of requests sent: <span id="attempts"></span></p>
24+
25+
<!-- How long it has ran for -->
26+
<p>Has ran for <span id="minutes"></span> minutes</p>
27+
28+
<!-- Display block number -->
29+
<p>Block number: <span id="call"></span></p>
30+
31+
<!-- Display result -->
32+
<p>Result: <span id="result"></span></p>
33+
34+
<script>
35+
36+
let web3;
37+
let attempt = 0;
38+
let intervalId;
39+
let start;
40+
let end;
41+
let result;
42+
// You will need to set mainnet infura provider
43+
web3 = new Web3("");
44+
45+
// constantly send requests through WS for 10 hours
46+
const sendRequests = () => {
47+
return new Promise((resolve, reject) => {
48+
// send a request in intervals of 10 minutes
49+
intervalId = setInterval( async() => {
50+
try{
51+
const block = await web3.eth.getBlock()
52+
attempt++;
53+
document.getElementById("attempts").innerText = attempt.toString();
54+
document.getElementById("call").innerText = block.number;
55+
document.getElementById("minutes").innerText = attempt*10;
56+
if (attempt === 144) { // after 10 hours
57+
clearInterval(intervalId);
58+
resolve("");
59+
document.getElementById("result").innerText = "success";
60+
}
61+
} catch (error) {
62+
clearInterval(intervalId);
63+
document.getElementById("result").innerText = "Error";
64+
reject(error);
65+
}
66+
},60000) // every 10 minutes
67+
})
68+
69+
}
70+
71+
const main = async () => {
72+
73+
try {
74+
start = new Date();
75+
document.getElementById("startTime").innerText = start.toTimeString();
76+
document.getElementById("attempts").innerText = attempt.toString();
77+
document.getElementById("endTime").innerText = "Currently running";
78+
const promise = sendRequests();
79+
await promise;
80+
} catch (e) {
81+
console.warn("error")
82+
}
83+
end = new Date();
84+
document.getElementById("endDate").innerText = new Date().toTimeString();
85+
86+
}
87+
main();
88+
</script>
89+
90+
<!-- You can include additional scripts at the end of the body section if needed -->
91+
92+
93+
</body>
94+
</html>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
This file is part of web3.js.
3+
4+
web3.js is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU Lesser General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
web3.js is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public License
15+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
/* eslint-disable */
18+
const { Web3 } = require('../../../../lib/commonjs');
19+
const secrets = require('../../../../../../.secrets.json');
20+
21+
let web3;
22+
let attempt = 0;
23+
let intervalId;
24+
let start;
25+
let end;
26+
27+
// constantly send requests through WS for 10 hours
28+
const sendRequests = () => {
29+
start = new Date();
30+
console.log("start:",start)
31+
return new Promise((resolve, reject) => {
32+
// send a request in intervals of 10 minutes
33+
intervalId = setInterval( async() => {
34+
try{
35+
const block = await web3.eth.getBlock()
36+
attempt++;
37+
console.log(block)
38+
console.log("successful calls:", attempt, "has ran for:", attempt*10, "minutes")
39+
if (attempt === 144) { // after 10 hours
40+
clearInterval(intervalId);
41+
resolve("");
42+
}
43+
} catch (error) {
44+
clearInterval(intervalId);
45+
reject(error);
46+
}
47+
},600000) // every 10 minutes
48+
})
49+
50+
}
51+
52+
const main = async () => {
53+
54+
try {
55+
// You will need to set mainnet infura provider
56+
const provider = secrets.MAINNET.WS;
57+
web3 = new Web3(provider);
58+
const promise = sendRequests();
59+
await promise;
60+
end = new Date();
61+
console.log("websocket test successful")
62+
} catch (e) {
63+
console.warn("error occured during ws test, on attempt: ", attempt, "program ran for: ", attempt ,"minutes with error: ", e)
64+
}
65+
console.log("start", start)
66+
console.log("end", end)
67+
process.exit();
68+
}
69+
70+
main();

0 commit comments

Comments
 (0)