This repository has been archived by the owner on Mar 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tests): add dial and listen tests
- Loading branch information
1 parent
1bd20d9
commit d50224d
Showing
10 changed files
with
302 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
**/node_modules/ | ||
**/*.log | ||
test/repo-tests* | ||
|
||
# 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 | ||
|
||
test |
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,10 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- "stable" | ||
|
||
before_install: | ||
- npm install -g npm | ||
|
||
script: | ||
- npm run lint |
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
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,74 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const expect = require('chai').expect | ||
const pull = require('pull-stream') | ||
const goodbye = require('pull-goodbye') | ||
|
||
module.exports = (common) => { | ||
describe('dial', () => { | ||
let addrs | ||
let transport | ||
let listener | ||
|
||
before((done) => { | ||
common.setup((err, _transport, _addrs) => { | ||
if (err) return done(err) | ||
transport = _transport | ||
addrs = _addrs | ||
done() | ||
}) | ||
}) | ||
|
||
after((done) => { | ||
common.teardown(done) | ||
}) | ||
|
||
beforeEach((done) => { | ||
listener = transport.createListener((conn) => { | ||
pull( | ||
conn, | ||
pull.map((x) => { | ||
if (x.toString() !== 'GOODBYE') { | ||
return new Buffer(x.toString() + '!') | ||
} | ||
return x | ||
}), | ||
conn | ||
) | ||
}) | ||
listener.listen(addrs[0], done) | ||
}) | ||
|
||
afterEach((done) => { | ||
listener.close(done) | ||
}) | ||
|
||
it('simple', (done) => { | ||
const s = goodbye({ | ||
source: pull.values([new Buffer('hey')]), | ||
sink: pull.collect((err, values) => { | ||
expect(err).to.not.exist | ||
expect( | ||
values | ||
).to.be.eql( | ||
[new Buffer('hey!')] | ||
) | ||
done() | ||
}) | ||
}) | ||
|
||
pull(s, transport.dial(addrs[0]), s) | ||
}) | ||
|
||
it('to non existent listener', (done) => { | ||
pull( | ||
transport.dial(addrs[1]), | ||
pull.onEnd((err) => { | ||
expect(err).to.exist | ||
done() | ||
}) | ||
) | ||
}) | ||
}) | ||
} |
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,12 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const dial = require('./dial-test') | ||
const listen = require('./listen-test') | ||
|
||
module.exports = (common) => { | ||
describe('interface-transport', () => { | ||
dial(common) | ||
listen(common) | ||
}) | ||
} |
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,118 @@ | ||
/* eslint max-nested-callbacks: ["error", 8] */ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const expect = require('chai').expect | ||
const pull = require('pull-stream') | ||
|
||
module.exports = (common) => { | ||
describe('listen', () => { | ||
let addrs | ||
let transport | ||
|
||
before((done) => { | ||
common.setup((err, _transport, _addrs) => { | ||
if (err) return done(err) | ||
transport = _transport | ||
addrs = _addrs | ||
done() | ||
}) | ||
}) | ||
|
||
after((done) => { | ||
common.teardown(done) | ||
}) | ||
|
||
it('simple', (done) => { | ||
const listener = transport.createListener((conn) => {}) | ||
listener.listen(addrs[0], () => { | ||
listener.close(done) | ||
}) | ||
}) | ||
|
||
it('close listener with connections, through timeout', (done) => { | ||
const finish = plan(3, done) | ||
const listener = transport.createListener((conn) => { | ||
pull(conn, conn) | ||
}) | ||
|
||
listener.listen(addrs[0], () => { | ||
const socket1 = transport.dial(addrs[0], () => { | ||
listener.close(finish) | ||
}) | ||
|
||
pull( | ||
transport.dial(addrs[0]), | ||
pull.onEnd(() => { | ||
finish() | ||
}) | ||
) | ||
|
||
pull( | ||
pull.values([Buffer('Some data that is never handled')]), | ||
socket1, | ||
pull.onEnd(() => { | ||
finish() | ||
}) | ||
) | ||
}) | ||
}) | ||
|
||
describe('events', () => { | ||
// TODO: figure out why it fails in the full test suite | ||
it.skip('connection', (done) => { | ||
const finish = plan(2, done) | ||
|
||
const listener = transport.createListener() | ||
|
||
listener.on('connection', (conn) => { | ||
expect(conn).to.exist | ||
finish() | ||
}) | ||
|
||
listener.listen(addrs[0], () => { | ||
transport.dial(addrs[0], () => { | ||
listener.close(finish) | ||
}) | ||
}) | ||
}) | ||
|
||
it('listening', (done) => { | ||
const listener = transport.createListener() | ||
listener.on('listening', () => { | ||
listener.close(done) | ||
}) | ||
listener.listen(addrs[0]) | ||
}) | ||
|
||
// TODO: how to get the listener to emit an error? | ||
it.skip('error', (done) => { | ||
const listener = transport.createListener() | ||
listener.on('error', (err) => { | ||
expect(err).to.exist | ||
listener.close(done) | ||
}) | ||
}) | ||
|
||
it('close', (done) => { | ||
const finish = plan(2, done) | ||
const listener = transport.createListener() | ||
listener.on('close', finish) | ||
|
||
listener.listen(addrs[0], () => { | ||
listener.close(finish) | ||
}) | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
function plan (n, done) { | ||
let i = 0 | ||
return (err) => { | ||
if (err) return done(err) | ||
i++ | ||
|
||
if (i === n) done() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.