Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stress Tests 3 - create long duration ws tests #6588

Merged
merged 14 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"test:e2e:mainnet:ws": "./scripts/test-runner.sh mainnet ws",
"test:e2e:sepolia:http": "./scripts/test-runner.sh sepolia http",
"test:e2e:sepolia:ws": "./scripts/test-runner.sh sepolia ws",
"test:manual":"node ./packages/web3/test/stress/manual/nodejs_test/connection.js",
luu-alex marked this conversation as resolved.
Show resolved Hide resolved
luu-alex marked this conversation as resolved.
Show resolved Hide resolved
"generate:accounts": "node ./scripts/gen_accounts.js",
"pre-blackbox": "yarn config set registry http://localhost:4873 && git init && git config --global user.email \"ci@github.com\" && git config --global user.name \"CI\"",
"post-blackbox": "./scripts/verdaccio.sh stop",
Expand Down
94 changes: 94 additions & 0 deletions packages/web3/test/stress/manual/browser_test/connection.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<!DOCTYPE html>
luu-alex marked this conversation as resolved.
Show resolved Hide resolved
<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> 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 packages/web3/test/stress/manual/nodejs_test/connection.js
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)
luu-alex marked this conversation as resolved.
Show resolved Hide resolved
}
console.log("start", start)
console.log("end", end)
process.exit();
}

main();
Loading