Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
fix(test): close with timeout (#54)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jacobheun authored Sep 16, 2019
1 parent d143f79 commit 583f02d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 49 deletions.
30 changes: 1 addition & 29 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,36 +1,8 @@
**/node_modules/
**/*.log
test/repo-tests*
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

# 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
docs
dist
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"coverage": "exit(0)",
"coverage-publish": "exit(0)"
},
"pre-commit": [
"pre-push": [
"lint"
],
"keywords": [
Expand Down
36 changes: 17 additions & 19 deletions src/listen-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ module.exports = (common) => {

it('close listener with connections, through timeout', async () => {
const upgradeSpy = sinon.spy(upgrader, 'upgradeInbound')
let finish
const done = new Promise((resolve) => {
finish = resolve
})

const listener = transport.createListener((conn) => {
expect(upgradeSpy.returned(conn)).to.equal(true)
Expand All @@ -64,21 +60,23 @@ module.exports = (common) => {
await listener.listen(addrs[0])

// Create two connections to the listener
const socket1 = await transport.dial(addrs[0])
await transport.dial(addrs[0])

pipe(
[Buffer.from('Some data that is never handled')],
socket1
).then(() => {
finish()
})

// Closer the listener (will take a couple of seconds to time out)
await listener.close()

// Pipe should have completed
await done
const [socket1] = await Promise.all([
transport.dial(addrs[0]),
transport.dial(addrs[0])
])

// Give the listener a chance to finish its upgrade
await new Promise(resolve => setTimeout(resolve, 0))

// Wait for the data send and close to finish
await Promise.all([
pipe(
[Buffer.from('Some data that is never handled')],
socket1
),
// Closer the listener (will take a couple of seconds to time out)
listener.close()
])

// 2 dials = 2 connections upgraded
expect(upgradeSpy.callCount).to.equal(2)
Expand Down

0 comments on commit 583f02d

Please sign in to comment.