mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-04-24 21:42:21 +00:00
fix(test): close with timeout (#54)
* fix(test): allow time for the listener to finish * chore: pre push instead of pre commit chore: clean up git ignore and add docs to list
This commit is contained in:
parent
d143f79ceb
commit
583f02d47a
30
.gitignore
vendored
30
.gitignore
vendored
@ -1,36 +1,8 @@
|
|||||||
**/node_modules/
|
**/node_modules/
|
||||||
**/*.log
|
**/*.log
|
||||||
test/repo-tests*
|
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
|
||||||
# Logs
|
|
||||||
logs
|
|
||||||
*.log
|
|
||||||
|
|
||||||
coverage
|
|
||||||
|
|
||||||
# Runtime data
|
|
||||||
pids
|
|
||||||
*.pid
|
|
||||||
*.seed
|
|
||||||
|
|
||||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
|
||||||
lib-cov
|
|
||||||
|
|
||||||
# Coverage directory used by tools like istanbul
|
# Coverage directory used by tools like istanbul
|
||||||
coverage
|
coverage
|
||||||
|
docs
|
||||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
|
||||||
.grunt
|
|
||||||
|
|
||||||
# node-waf configuration
|
|
||||||
.lock-wscript
|
|
||||||
|
|
||||||
build
|
|
||||||
|
|
||||||
# Dependency directory
|
|
||||||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
|
|
||||||
node_modules
|
|
||||||
|
|
||||||
lib
|
|
||||||
dist
|
dist
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
"coverage": "exit(0)",
|
"coverage": "exit(0)",
|
||||||
"coverage-publish": "exit(0)"
|
"coverage-publish": "exit(0)"
|
||||||
},
|
},
|
||||||
"pre-commit": [
|
"pre-push": [
|
||||||
"lint"
|
"lint"
|
||||||
],
|
],
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
@ -50,10 +50,6 @@ module.exports = (common) => {
|
|||||||
|
|
||||||
it('close listener with connections, through timeout', async () => {
|
it('close listener with connections, through timeout', async () => {
|
||||||
const upgradeSpy = sinon.spy(upgrader, 'upgradeInbound')
|
const upgradeSpy = sinon.spy(upgrader, 'upgradeInbound')
|
||||||
let finish
|
|
||||||
const done = new Promise((resolve) => {
|
|
||||||
finish = resolve
|
|
||||||
})
|
|
||||||
|
|
||||||
const listener = transport.createListener((conn) => {
|
const listener = transport.createListener((conn) => {
|
||||||
expect(upgradeSpy.returned(conn)).to.equal(true)
|
expect(upgradeSpy.returned(conn)).to.equal(true)
|
||||||
@ -64,21 +60,23 @@ module.exports = (common) => {
|
|||||||
await listener.listen(addrs[0])
|
await listener.listen(addrs[0])
|
||||||
|
|
||||||
// Create two connections to the listener
|
// Create two connections to the listener
|
||||||
const socket1 = await transport.dial(addrs[0])
|
const [socket1] = await Promise.all([
|
||||||
await transport.dial(addrs[0])
|
transport.dial(addrs[0]),
|
||||||
|
transport.dial(addrs[0])
|
||||||
|
])
|
||||||
|
|
||||||
pipe(
|
// Give the listener a chance to finish its upgrade
|
||||||
[Buffer.from('Some data that is never handled')],
|
await new Promise(resolve => setTimeout(resolve, 0))
|
||||||
socket1
|
|
||||||
).then(() => {
|
|
||||||
finish()
|
|
||||||
})
|
|
||||||
|
|
||||||
// Closer the listener (will take a couple of seconds to time out)
|
// Wait for the data send and close to finish
|
||||||
await listener.close()
|
await Promise.all([
|
||||||
|
pipe(
|
||||||
// Pipe should have completed
|
[Buffer.from('Some data that is never handled')],
|
||||||
await done
|
socket1
|
||||||
|
),
|
||||||
|
// Closer the listener (will take a couple of seconds to time out)
|
||||||
|
listener.close()
|
||||||
|
])
|
||||||
|
|
||||||
// 2 dials = 2 connections upgraded
|
// 2 dials = 2 connections upgraded
|
||||||
expect(upgradeSpy.callCount).to.equal(2)
|
expect(upgradeSpy.callCount).to.equal(2)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user