Skip to content
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

Adds test-timing keepAlive test #2590

Merged
merged 2 commits into from Mar 16, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 47 additions & 0 deletions tests/test-timing.js
Expand Up @@ -88,6 +88,53 @@ tape('redirected request is timed with rollup', function(t) {
})
})

tape('keepAlive is timed', function(t) {
var agent = new require('http').Agent({ keepAlive: true })
var options = { time: true, agent: agent }
var start1 = new Date().getTime()
request('http://localhost:' + plain_server.port + '/', options, function(err1, res1, body1) {
var end1 = new Date().getTime()

// ensure the first request's timestamps look ok
t.equal((res1.timingStart >= start1), true)
t.equal((start1 <= end1), true)

t.equal((res1.timings.socket >= 0), true)
t.equal((res1.timings.lookup >= res1.timings.socket), true)
t.equal((res1.timings.connect >= res1.timings.lookup), true)
t.equal((res1.timings.response >= res1.timings.connect), true)

var start2 = new Date().getTime()
request('http://localhost:' + plain_server.port + '/', options, function(err2, res2, body2) {
var end2 = new Date().getTime()

// ensure the second request's timestamps look ok
t.equal((res2.timingStart >= start2), true)
t.equal((start2 <= end2), true)

// ensure socket==lookup==connect for the second request
t.equal((res2.timings.socket >= 0), true)
t.equal((res2.timings.lookup == res2.timings.socket), true)
t.equal((res2.timings.connect == res2.timings.lookup), true)
t.equal((res2.timings.response >= res2.timings.connect), true)

// explicitly shut down the agent
if (typeof agent.destroy === 'function') {
agent.destroy()
} else {
// node < 0.12
Object.keys(agent.sockets).forEach(function (name) {
agent.sockets[name].forEach(function (socket) {
socket.end()
})
})
}

t.end()
})
})
})

tape('cleanup', function(t) {
plain_server.close(function() {
t.end()
Expand Down