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
Add option to time request/response cycle (including rollup of redirects) #1459
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
'use strict' | ||
|
||
var http = require('http') | ||
, server = require('./server') | ||
, request = require('../index') | ||
, tape = require('tape') | ||
|
||
var plain_server = server.createServer() | ||
, redirect_mock_time = 10 | ||
|
||
tape('setup', function(t) { | ||
plain_server.listen(plain_server.port, function() { | ||
plain_server.on('/', function (req, res) { | ||
res.writeHead(200) | ||
res.end('plain') | ||
}) | ||
plain_server.on('/redir', function (req, res) { | ||
// fake redirect delay to ensure strong signal for rollup check | ||
setTimeout(function() { | ||
res.writeHead(301, { 'location': 'http://localhost:' + plain_server.port + '/' }) | ||
res.end() | ||
}, redirect_mock_time) | ||
}) | ||
|
||
request('http://localhost:' + plain_server.port + '/', {}, function(err, res, body) { | ||
t.equal(err, null) | ||
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. why do we have this test here? 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. to ensure that, when redirects are handled inline, the time reported on the response is the sum of all request times, rather than just the time taken by the last request/response cycle 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. Im confused, you comment seems to be explaining a different test. 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. Wups, you're right - that's what I get for replying from my phone. |
||
}) | ||
|
||
t.end() | ||
}) | ||
}) | ||
|
||
tape('no-op', function(t) { | ||
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. any reason we have this test? |
||
t.end() | ||
}) | ||
|
||
tape('non-redirected request is timed', function(t) { | ||
var options = {time: true} | ||
request('http://localhost:' + plain_server.port + '/', options, function(err, res, body) { | ||
t.equal(err, null) | ||
t.equal(typeof res.elapsedTime, 'number') | ||
t.equal((res.elapsedTime > 0), true) | ||
t.end() | ||
}) | ||
}) | ||
|
||
tape('redirected request is timed with rollup', function(t) { | ||
var options = {time: true} | ||
request('http://localhost:' + plain_server.port + '/redir', options, function(err, res, body) { | ||
t.equal(err, null) | ||
t.equal(typeof res.elapsedTime, 'number') | ||
t.equal((res.elapsedTime > 0), true) | ||
t.equal((res.elapsedTime > redirect_mock_time), true) | ||
t.end() | ||
}) | ||
}) | ||
|
||
tape('cleanup', function(t) { | ||
plain_server.close(function() { | ||
t.end() | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we just define
self.startTime
to benew Date().getTime()
?