-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Alex
authored
Nov 20, 2023
1 parent
af91519
commit 2785782
Showing
4 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
packages/web3/test/manual/long_ws_tests/browser_test/connection.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Manual browser tests</title> | ||
<!-- To Run --> | ||
<script src="../../../../dist/web3.min.js"> | ||
</script> | ||
</head> | ||
<body> | ||
|
||
<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> | ||
<p> Have this html test open in a browser of your choice</p> | ||
<p> Keep dev console open in case of any unintended errors occur </p> | ||
<!-- Display start date --> | ||
<p>Start time: <span id="startTime"></span></p> | ||
|
||
<!-- Display end date --> | ||
<p>End Time: <span id="endTime"></span></p> | ||
|
||
<!-- Display attempts made --> | ||
<p>Number of requests sent: <span id="attempts"></span></p> | ||
|
||
<!-- How long it has ran for --> | ||
<p>Has ran for <span id="minutes"></span> minutes</p> | ||
|
||
<!-- Display block number --> | ||
<p>Block number: <span id="call"></span></p> | ||
|
||
<!-- Display result --> | ||
<p>Result: <span id="result"></span></p> | ||
|
||
<script> | ||
|
||
let web3; | ||
let attempt = 0; | ||
let intervalId; | ||
let start; | ||
let end; | ||
let result; | ||
// You will need to set mainnet infura provider | ||
web3 = new Web3(""); | ||
|
||
// constantly send requests through WS for 10 hours | ||
const sendRequests = () => { | ||
return new Promise((resolve, reject) => { | ||
// send a request in intervals of 10 minutes | ||
intervalId = setInterval( async() => { | ||
try{ | ||
const block = await web3.eth.getBlock() | ||
attempt++; | ||
document.getElementById("attempts").innerText = attempt.toString(); | ||
document.getElementById("call").innerText = block.number; | ||
document.getElementById("minutes").innerText = attempt*10; | ||
if (attempt === 144) { // after 10 hours | ||
clearInterval(intervalId); | ||
resolve(""); | ||
document.getElementById("result").innerText = "success"; | ||
} | ||
} catch (error) { | ||
clearInterval(intervalId); | ||
document.getElementById("result").innerText = "Error"; | ||
reject(error); | ||
} | ||
},60000) // every 10 minutes | ||
}) | ||
|
||
} | ||
|
||
const main = async () => { | ||
|
||
try { | ||
start = new Date(); | ||
document.getElementById("startTime").innerText = start.toTimeString(); | ||
document.getElementById("attempts").innerText = attempt.toString(); | ||
document.getElementById("endTime").innerText = "Currently running"; | ||
const promise = sendRequests(); | ||
await promise; | ||
} catch (e) { | ||
console.warn("error") | ||
} | ||
end = new Date(); | ||
document.getElementById("endDate").innerText = new Date().toTimeString(); | ||
|
||
} | ||
main(); | ||
</script> | ||
|
||
<!-- You can include additional scripts at the end of the body section if needed --> | ||
|
||
|
||
</body> | ||
</html> |
70 changes: 70 additions & 0 deletions
70
packages/web3/test/manual/long_ws_tests/nodejs_test/long_connection_ws.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
This file is part of web3.js. | ||
web3.js is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
web3.js is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public License | ||
along with web3.js. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
/* eslint-disable */ | ||
const { Web3 } = require('../../../../lib/commonjs'); | ||
const secrets = require('../../../../../../.secrets.json'); | ||
|
||
let web3; | ||
let attempt = 0; | ||
let intervalId; | ||
let start; | ||
let end; | ||
|
||
// constantly send requests through WS for 10 hours | ||
const sendRequests = () => { | ||
start = new Date(); | ||
console.log("start:",start) | ||
return new Promise((resolve, reject) => { | ||
// send a request in intervals of 10 minutes | ||
intervalId = setInterval( async() => { | ||
try{ | ||
const block = await web3.eth.getBlock() | ||
attempt++; | ||
console.log(block) | ||
console.log("successful calls:", attempt, "has ran for:", attempt*10, "minutes") | ||
if (attempt === 144) { // after 10 hours | ||
clearInterval(intervalId); | ||
resolve(""); | ||
} | ||
} catch (error) { | ||
clearInterval(intervalId); | ||
reject(error); | ||
} | ||
},600000) // every 10 minutes | ||
}) | ||
|
||
} | ||
|
||
const main = async () => { | ||
|
||
try { | ||
// You will need to set mainnet infura provider | ||
const provider = secrets.MAINNET.WS; | ||
web3 = new Web3(provider); | ||
const promise = sendRequests(); | ||
await promise; | ||
end = new Date(); | ||
console.log("websocket test successful") | ||
} catch (e) { | ||
console.warn("error occured during ws test, on attempt: ", attempt, "program ran for: ", attempt ,"minutes with error: ", e) | ||
} | ||
console.log("start", start) | ||
console.log("end", end) | ||
process.exit(); | ||
} | ||
|
||
main(); |