-
-
Notifications
You must be signed in to change notification settings - Fork 674
feat: port client-connect, client-dispatch, client-errors test to node:test
#2591
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
00c7cd2
`client-connect`
4f4bfb1
`client-dispatch`
74d6d7e
`client-errors`
c643b85
Use `done` instead of `t.end`
5e1d701
Fix `t.after`
7aaff7a
Update `return client.close()`
b36ead7
Update `client-errors` without `parser error` tests
159c39c
Add FIXME comment
eca036c
Use `closeServerAsPromise` for `client-dispatch`
62dd4ff
Use `closeServerAsPromise` for `client-connect`
bc36686
Leave some tests on tap
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -6,277 +6,7 @@ const http = require('http') | |
| const EE = require('events') | ||
| const { kBusy } = require('../lib/core/symbols') | ||
|
|
||
| test('basic connect', (t) => { | ||
| t.plan(3) | ||
|
|
||
| const server = http.createServer((c) => { | ||
| t.fail() | ||
| }) | ||
| server.on('connect', (req, socket, firstBodyChunk) => { | ||
| socket.write('HTTP/1.1 200 Connection established\r\n\r\n') | ||
|
|
||
| let data = firstBodyChunk.toString() | ||
| socket.on('data', (buf) => { | ||
| data += buf.toString() | ||
| }) | ||
|
|
||
| socket.on('end', () => { | ||
| socket.end(data) | ||
| }) | ||
| }) | ||
| t.teardown(server.close.bind(server)) | ||
|
|
||
| server.listen(0, async () => { | ||
| const client = new Client(`http://localhost:${server.address().port}`) | ||
| t.teardown(client.close.bind(client)) | ||
|
|
||
| const signal = new EE() | ||
| const promise = client.connect({ | ||
| signal, | ||
| path: '/' | ||
| }) | ||
| t.equal(signal.listenerCount('abort'), 1) | ||
| const { socket } = await promise | ||
| t.equal(signal.listenerCount('abort'), 0) | ||
|
|
||
| let recvData = '' | ||
| socket.on('data', (d) => { | ||
| recvData += d | ||
| }) | ||
|
|
||
| socket.on('end', () => { | ||
| t.equal(recvData.toString(), 'Body') | ||
| }) | ||
|
|
||
| socket.write('Body') | ||
| socket.end() | ||
| }) | ||
| }) | ||
|
|
||
| test('connect error', (t) => { | ||
| t.plan(1) | ||
|
|
||
| const server = http.createServer((c) => { | ||
| t.fail() | ||
| }) | ||
| server.on('connect', (req, socket, firstBodyChunk) => { | ||
| socket.destroy() | ||
| }) | ||
| t.teardown(server.close.bind(server)) | ||
|
|
||
| server.listen(0, async () => { | ||
| const client = new Client(`http://localhost:${server.address().port}`) | ||
| t.teardown(client.close.bind(client)) | ||
|
|
||
| try { | ||
| await client.connect({ | ||
| path: '/' | ||
| }) | ||
| } catch (err) { | ||
| t.ok(err) | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| test('connect invalid opts', (t) => { | ||
| t.plan(6) | ||
|
|
||
| const client = new Client('http://localhost:5432') | ||
|
|
||
| client.connect(null, err => { | ||
| t.type(err, errors.InvalidArgumentError) | ||
| t.equal(err.message, 'invalid opts') | ||
| }) | ||
|
|
||
| try { | ||
| client.connect(null, null) | ||
| t.fail() | ||
| } catch (err) { | ||
| t.type(err, errors.InvalidArgumentError) | ||
| t.equal(err.message, 'invalid opts') | ||
| } | ||
|
|
||
| try { | ||
| client.connect({ path: '/' }, null) | ||
| t.fail() | ||
| } catch (err) { | ||
| t.type(err, errors.InvalidArgumentError) | ||
| t.equal(err.message, 'invalid callback') | ||
| } | ||
| }) | ||
|
|
||
| test('connect wait for empty pipeline', (t) => { | ||
| t.plan(7) | ||
|
|
||
| let canConnect = false | ||
| const server = http.createServer((req, res) => { | ||
| res.end() | ||
| canConnect = true | ||
| }) | ||
| server.on('connect', (req, socket, firstBodyChunk) => { | ||
| t.equal(canConnect, true) | ||
| socket.write('HTTP/1.1 200 Connection established\r\n\r\n') | ||
|
|
||
| let data = firstBodyChunk.toString() | ||
| socket.on('data', (buf) => { | ||
| data += buf.toString() | ||
| }) | ||
|
|
||
| socket.on('end', () => { | ||
| socket.end(data) | ||
| }) | ||
| }) | ||
| t.teardown(server.close.bind(server)) | ||
|
|
||
| server.listen(0, async () => { | ||
| const client = new Client(`http://localhost:${server.address().port}`, { | ||
| pipelining: 3 | ||
| }) | ||
| t.teardown(client.close.bind(client)) | ||
|
|
||
| client.request({ | ||
| path: '/', | ||
| method: 'GET' | ||
| }, (err) => { | ||
| t.error(err) | ||
| }) | ||
| client.once('connect', () => { | ||
| process.nextTick(() => { | ||
| t.equal(client[kBusy], false) | ||
|
|
||
| client.connect({ | ||
| path: '/' | ||
| }, (err, { socket }) => { | ||
| t.error(err) | ||
| let recvData = '' | ||
| socket.on('data', (d) => { | ||
| recvData += d | ||
| }) | ||
|
|
||
| socket.on('end', () => { | ||
| t.equal(recvData.toString(), 'Body') | ||
| }) | ||
|
|
||
| socket.write('Body') | ||
| socket.end() | ||
| }) | ||
| t.equal(client[kBusy], true) | ||
|
|
||
| client.request({ | ||
| path: '/', | ||
| method: 'GET' | ||
| }, (err) => { | ||
| t.error(err) | ||
| }) | ||
| }) | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| test('connect aborted', (t) => { | ||
| t.plan(6) | ||
|
|
||
| const server = http.createServer((req, res) => { | ||
| t.fail() | ||
| }) | ||
| server.on('connect', (req, c, firstBodyChunk) => { | ||
| t.fail() | ||
| }) | ||
| t.teardown(server.close.bind(server)) | ||
|
|
||
| server.listen(0, () => { | ||
| const client = new Client(`http://localhost:${server.address().port}`, { | ||
| pipelining: 3 | ||
| }) | ||
| t.teardown(client.destroy.bind(client)) | ||
|
|
||
| const signal = new EE() | ||
| client.connect({ | ||
| path: '/', | ||
| signal, | ||
| opaque: 'asd' | ||
| }, (err, { opaque }) => { | ||
| t.equal(opaque, 'asd') | ||
| t.equal(signal.listenerCount('abort'), 0) | ||
| t.type(err, errors.RequestAbortedError) | ||
| }) | ||
| t.equal(client[kBusy], true) | ||
| t.equal(signal.listenerCount('abort'), 1) | ||
| signal.emit('abort') | ||
|
|
||
| client.close(() => { | ||
| t.pass() | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| test('basic connect error', (t) => { | ||
| t.plan(2) | ||
|
|
||
| const server = http.createServer((c) => { | ||
| t.fail() | ||
| }) | ||
| server.on('connect', (req, socket, firstBodyChunk) => { | ||
| socket.write('HTTP/1.1 200 Connection established\r\n\r\n') | ||
|
|
||
| let data = firstBodyChunk.toString() | ||
| socket.on('data', (buf) => { | ||
| data += buf.toString() | ||
| }) | ||
|
|
||
| socket.on('end', () => { | ||
| socket.end(data) | ||
| }) | ||
| }) | ||
| t.teardown(server.close.bind(server)) | ||
|
|
||
| server.listen(0, async () => { | ||
| const client = new Client(`http://localhost:${server.address().port}`) | ||
| t.teardown(client.close.bind(client)) | ||
|
|
||
| const _err = new Error() | ||
| client.connect({ | ||
| path: '/' | ||
| }, (err, { socket }) => { | ||
| t.error(err) | ||
| socket.on('error', (err) => { | ||
| t.equal(err, _err) | ||
| }) | ||
| throw _err | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| test('connect invalid signal', (t) => { | ||
| t.plan(2) | ||
|
|
||
| const server = http.createServer((req, res) => { | ||
| t.fail() | ||
| }) | ||
| server.on('connect', (req, c, firstBodyChunk) => { | ||
| t.fail() | ||
| }) | ||
| t.teardown(server.close.bind(server)) | ||
|
|
||
| server.listen(0, () => { | ||
| const client = new Client(`http://localhost:${server.address().port}`) | ||
| t.teardown(client.destroy.bind(client)) | ||
|
|
||
| client.on('disconnect', () => { | ||
| t.fail() | ||
| }) | ||
|
|
||
| client.connect({ | ||
| path: '/', | ||
| signal: 'error', | ||
| opaque: 'asd' | ||
| }, (err, { opaque }) => { | ||
| t.equal(opaque, 'asd') | ||
| t.type(err, errors.InvalidArgumentError) | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| // TODO: move to test/node-test/client-connect.js | ||
| test('connect aborted after connect', (t) => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When porting this test to |
||
| t.plan(3) | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.