forked from Bitcoin-com/bitbox-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add steps to reproduce issue Bitcoin-com#173 showing redundant connec…
…tions.
- Loading branch information
Showing
2 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
test/e2e/count-connections-issue-173/countConnectionsBitSocket.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,57 @@ | ||
const BITBOX = require("../../../lib/BITBOX").BITBOX; | ||
const { exec } = require('child_process'); | ||
|
||
const bitbox = new BITBOX(); | ||
const socket = new bitbox.Socket(); | ||
|
||
function countSockets(stage) { | ||
return new Promise((resolve, reject) => { | ||
// Call the lsof system command for outgoing internet connections. | ||
exec(`lsof -i -n -P | grep ${process.pid}`, (err, stdout, stderr) => { | ||
// Print list of open connections allowing a visual count to be done. | ||
console.log(`Outbound connections from this node process ${stage}:\n${stdout}`); | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
function sleep(ms) { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} | ||
|
||
(async () => { | ||
|
||
await countSockets("before calling listen"); | ||
|
||
//First call to listen() which should create new connection. | ||
socket.listen({"v": 3, "q": {"find": {}}}, | ||
(message) => { | ||
console.log("Callback from first query invoked."); | ||
}); | ||
|
||
//Second call to listen() which should share connection with first call. | ||
socket.listen({"v": 3, "q": {"find": {}}}, | ||
(message) => { | ||
console.log("Callback from first query invoked."); | ||
}); | ||
|
||
// listen doesn't return a promise so wait 100ms for connections to establish. | ||
await sleep(100); | ||
|
||
await countSockets("after calling listen twice"); | ||
|
||
// now close the socket | ||
socket.close(); | ||
|
||
// callback from close() is short-circuited so give it 100ms to clean up. | ||
await sleep(100); | ||
|
||
// check if any zombie connections remaining | ||
await countSockets("after calling close (zombie connections)"); | ||
|
||
// exit process | ||
process.exit(); | ||
|
||
})(); | ||
|
||
|
55 changes: 55 additions & 0 deletions
55
test/e2e/count-connections-issue-173/countConnectionsSocketIO.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,55 @@ | ||
const BITBOX = require("../../../lib/BITBOX").BITBOX; | ||
const { exec } = require('child_process'); | ||
|
||
const bitbox = new BITBOX(); | ||
const socket = new bitbox.Socket(); | ||
|
||
function countSockets(stage) { | ||
return new Promise((resolve, reject) => { | ||
// Call the lsof system command for outgoing internet connections. | ||
exec(`lsof -i -n -P | grep ${process.pid}`, (err, stdout, stderr) => { | ||
// Print list of open connections allowing a visual count to be done. | ||
console.log(`Outbound connections from this node process ${stage}:\n${stdout}`); | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
function sleep(ms) { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} | ||
|
||
(async () => { | ||
|
||
await countSockets("before calling listen"); | ||
|
||
//First call to listen() which should create new connection. | ||
socket.listen("transactions", (message) => { | ||
console.log("Received a transaction."); | ||
}); | ||
|
||
//Second call to listen() which should share connection with first call. | ||
socket.listen("blocks", (message) => { | ||
console.log("Received a block."); | ||
}); | ||
|
||
// listen doesn't return a promise so wait 100ms for connections to establish. | ||
await sleep(100); | ||
|
||
await countSockets("after calling listen twice"); | ||
|
||
// now close the socket | ||
socket.close(); | ||
|
||
// callback from close() is short-circuited so give it 100ms to clean up. | ||
await sleep(100); | ||
|
||
// check if any zombie connections remaining | ||
await countSockets("after calling close (zombie connections)"); | ||
|
||
// exit process | ||
process.exit(); | ||
|
||
})(); | ||
|
||
|