-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: emit diagnostics_channel upon handling request
- Loading branch information
Showing
16 changed files
with
690 additions
and
79 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
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
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 @@ | ||
'use strict' | ||
|
||
const t = require('tap') | ||
const diagnostics = require('dc-polyfill') | ||
const test = t.test | ||
const sget = require('simple-get').concat | ||
const Fastify = require('../..') | ||
const { getServerUrl } = require('../helper') | ||
const Request = require('../../lib/request') | ||
const Reply = require('../../lib/reply') | ||
|
||
test('diagnostics channel sync events fire in expected order', t => { | ||
t.plan(9) | ||
let callOrder = 0 | ||
let firstEncounteredMessage | ||
|
||
diagnostics.subscribe('tracing:fastify.request.handler:start', (msg) => { | ||
t.equal(callOrder++, 0) | ||
firstEncounteredMessage = msg | ||
t.ok(msg.request instanceof Request) | ||
t.ok(msg.reply instanceof Reply) | ||
}) | ||
|
||
diagnostics.subscribe('tracing:fastify.request.handler:end', (msg) => { | ||
t.ok(msg.request instanceof Request) | ||
t.ok(msg.reply instanceof Reply) | ||
t.equal(callOrder++, 1) | ||
t.equal(msg, firstEncounteredMessage) | ||
}) | ||
|
||
diagnostics.subscribe('tracing:fastify.request.handler:error', (msg) => { | ||
t.fail('should not trigger error channel') | ||
}) | ||
|
||
const fastify = Fastify() | ||
fastify.route({ | ||
method: 'GET', | ||
url: '/', | ||
handler: function (req, reply) { | ||
reply.callNotFound() | ||
} | ||
}) | ||
|
||
fastify.listen({ port: 0 }, function (err) { | ||
if (err) t.error(err) | ||
|
||
t.teardown(() => { fastify.close() }) | ||
|
||
sget({ | ||
method: 'GET', | ||
url: getServerUrl(fastify) + '/' | ||
}, (err, response, body) => { | ||
t.error(err) | ||
t.equal(response.statusCode, 404) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.