Skip to content

Commit

Permalink
Merge pull request #957 from NodeJS-agent/nwolfe/tap-5
Browse files Browse the repository at this point in the history
Tap 7
  • Loading branch information
Martin Kuba committed Sep 30, 2016
2 parents f71f0db + 2cd56f6 commit 0181a7b
Show file tree
Hide file tree
Showing 130 changed files with 2,159 additions and 2,799 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
],
"devDependencies": {
"mocha": "*",
"tap": "0.7.1",
"tap": "^7.1.2",
"eslint": "^2.9.0"
},
"repository": {
Expand Down
17 changes: 10 additions & 7 deletions test/integration/agent/multiple.tap.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
'use strict'

var assert = require('chai').assert
var test = require('tap').test

process.env.NEW_RELIC_ENABLED = false
test('Multiple require("newrelic")', function(t) {
process.env.NEW_RELIC_ENABLED = false

var path = require.resolve('../../../index.js')
var first = require(path)
var path = require.resolve('../../../index.js')
var first = require(path)

delete require.cache[path]
delete require.cache[path]

var second = require(path)
var second = require(path)

assert.equal(first, second)
t.equal(first, second)
t.end()
})
5 changes: 3 additions & 2 deletions test/integration/agent/send-errors.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ test('Agent#_sendErrors', function(t) {
_testSendErrors(t, agent)
})

t.autoend()

function _testSendErrors(t, agent) {
t.plan(6)
t.plan(7)

agent.start(function(err) {
if (!t.notOk(err, 'should connect without error')) {
Expand Down Expand Up @@ -71,7 +73,6 @@ test('Agent#_sendErrors', function(t) {

agent.stop(function(error) {
t.notOk(error, "stopped without error")

t.end()
})
})
Expand Down
39 changes: 19 additions & 20 deletions test/integration/collector-remote-method.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ test("DataSender (callback style) talking to fake collector", function (t) {
}
var method = new RemoteMethod('get_redirect_host', config)

var suite = this
collector({port : 8765}, function (error, server) {
if (error) {
t.fail(error)
return t.end()
}

suite.tearDown(function cb_tearDown() {
t.tearDown(function() {
server.close()
})

Expand All @@ -50,52 +49,48 @@ test("DataSender (callback style) talking to fake collector", function (t) {
test("remote method to get redirect host", function (t) {

t.test("https with custom certificate", function(t) {
var test = t
t.plan(3)
var method = createRemoteMethod(true, true)

// create mock collector
startMockCollector(true, function(err, server) {
startMockCollector(t, true, function(err, server) {
method.invoke([], function(error, returnValue, json) {
validateResponse(test, error, returnValue)
server.close()
validateResponse(t, error, returnValue)
t.end()
})
})
})

t.test("http without custom certificate", function(t) {
var test = t
t.plan(3)
var method = createRemoteMethod(false, false)

// create mock collector
startMockCollector(false, function(err, server) {
startMockCollector(t, false, function(err, server) {
method.invoke([], function(error, returnValue, json) {
validateResponse(test, error, returnValue)
server.close()
validateResponse(t, error, returnValue)
t.end()
})
})
})

t.test("http with custom certificate", function(t) {
var test = t
t.plan(3)
var method = createRemoteMethod(false, true)

// create mock collector
startMockCollector(false, function(err, server) {
startMockCollector(t, false, function(err, server) {
method.invoke([], function(error, returnValue, json) {
validateResponse(test, error, returnValue)
server.close()
validateResponse(t, error, returnValue)
t.end()
})
})
})
t.autoend()

function validateResponse(t, error, returnValue) {
if (error) {
t.fail(error)
}
t.equal(returnValue, 'some-collector-url', 'got back expected response')
t.notOk(error, 'should not have an error')
t.equal(returnValue, 'some-collector-url', 'should get expected response')
}

function createRemoteMethod(ssl, useCertificate) {
Expand All @@ -117,7 +112,7 @@ test("remote method to get redirect host", function (t) {
return method
}

function startMockCollector(ssl, startedCallback) {
function startMockCollector(t, ssl, startedCallback) {
var opts = {
port: 8765
}
Expand All @@ -135,9 +130,13 @@ test("remote method to get redirect host", function (t) {
startedCallback(err, this)
})

t.tearDown(function() {
server.close()
})

function responder(req, res) {
var parsed = url.parse(req.url, true)
t.equal(parsed.query['method'], 'get_redirect_host', 'got redirect host request')
t.equal(parsed.query['method'], 'get_redirect_host', 'should get redirect host request')
res.write(JSON.stringify({
"return_value": "some-collector-url"
}))
Expand Down
91 changes: 57 additions & 34 deletions test/integration/connection-failure/503.tap.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict'

var test = require('tap').test
var nock = require('nock')
var test = require('tap').test
var nock = require('nock')
var configurator = require('../../../lib/config.js')
var Agent = require('../../../lib/agent.js')
var Transaction = require('../../../lib/transaction')
var mockAWSInfo = require('../../lib/nock/aws.js').mockAWSInfo
var Agent = require('../../../lib/agent.js')
var Transaction = require('../../../lib/transaction')
var mockAWSInfo = require('../../lib/nock/aws.js').mockAWSInfo


// XXX Remove this when deprecating Node v0.8.
Expand All @@ -14,13 +14,14 @@ if (!global.setImmediate) {
global.setTimeout(fn, 0)
}
}

nock.disableNetConnect()

test("harvesting with a mocked collector that returns 503 after connect", function (t) {
var RUN_ID = 1337
, url = 'https://collector.newrelic.com'
, agent = new Agent(configurator.initialize())
, transaction = new Transaction(agent)
var RUN_ID = 1337
var url = 'https://collector.newrelic.com'
var agent = new Agent(configurator.initialize())
var transaction = new Transaction(agent)


function path(method, runID) {
Expand All @@ -46,8 +47,8 @@ test("harvesting with a mocked collector that returns 503 after connect", functi
.reply(200, {return_value : []})

var sendMetrics = nock(url).post(path('metric_data', RUN_ID)).reply(503, returned)
, sendErrors = nock(url).post(path('error_data', RUN_ID)).reply(503, returned)
, sendTrace = nock(url).post(path('transaction_sample_data', RUN_ID))
var sendErrors = nock(url).post(path('error_data', RUN_ID)).reply(503, returned)
var sendTrace = nock(url).post(path('transaction_sample_data', RUN_ID))
.reply(503, returned)


Expand Down Expand Up @@ -86,10 +87,12 @@ test("harvesting with a mocked collector that returns 503 after connect", functi
test("merging metrics and errors after a 503", function (t) {
t.plan(6)

var RUN_ID = 1338
, url = 'https://collector.newrelic.com'
, agent = new Agent(configurator.initialize())
, transaction = new Transaction(agent)
var RUN_ID = 1338
var url = 'https://collector.newrelic.com'
var agentConfig = configurator.initialize()
agentConfig.utilization.detect_docker = false
var agent = new Agent(agentConfig)
var transaction = new Transaction(agent)

transaction.name = 'trans1'

Expand Down Expand Up @@ -134,9 +137,6 @@ test("merging metrics and errors after a 503", function (t) {
t.deepEqual(merged[1], 'trans1', "found scope in merged error")
t.deepEqual(merged[2], 'test error', "found message in merged error")

console.log('asdfasdfasdfasfasd')
console.log(agent.metrics.toJSON())

t.deepEqual(
agent.metrics.toJSON(),
[[
Expand All @@ -149,8 +149,7 @@ test("merging metrics and errors after a 503", function (t) {
sumOfSquares : 0,
callCount : 1
}
],
[
],[
{name : "Errors/all"},
{
total : 0,
Expand All @@ -160,8 +159,7 @@ test("merging metrics and errors after a 503", function (t) {
sumOfSquares : 0,
callCount : 1
}
],
[
],[
{name : "Errors/allWeb"},
{
total : 0,
Expand All @@ -171,8 +169,7 @@ test("merging metrics and errors after a 503", function (t) {
sumOfSquares : 0,
callCount : 0
}
],
[
],[
{name : "Errors/allOther"},
{
total : 0,
Expand All @@ -182,8 +179,30 @@ test("merging metrics and errors after a 503", function (t) {
sumOfSquares : 0,
callCount : 1
}
],
[{
],[
// Bluebird is a dependency of tap, and since tap is loaded before
// the agent, it will be caught in the "Uninstrumented" metrics.
{name: "Supportability/Uninstrumented"},
{
total : 0,
totalExclusive : 0,
min : 0,
max : 0,
sumOfSquares : 0,
callCount : 1
}
],[
{name: "Supportability/Uninstrumented/bluebird"},
{
total : 0,
totalExclusive : 0,
min : 0,
max : 0,
sumOfSquares : 0,
callCount : 1
}
],[
{
"name" : "Supportability/Events/Customer/Dropped" // != undefined
},{
"total" : 0, // != undefined
Expand All @@ -192,8 +211,9 @@ test("merging metrics and errors after a 503", function (t) {
"max" : 0, // != undefined
"sumOfSquares" : 0, // != undefined
"callCount" : 0 // != undefined
}], // != undefined
[{
}
],[
{
"name" : "Supportability/Events/Customer/Seen" // != undefined
},{
"total" : 0, // != undefined
Expand All @@ -202,8 +222,9 @@ test("merging metrics and errors after a 503", function (t) {
"max" : 0, // != undefined
"sumOfSquares" : 0, // != undefined
"callCount" : 0 // != undefined
}], // != undefined
[{
}
],[
{
"name" : "Supportability/Events/Customer/Sent" // != undefined
},{
"total" : 0, // != undefined
Expand All @@ -212,8 +233,9 @@ test("merging metrics and errors after a 503", function (t) {
"max" : 0, // != undefined
"sumOfSquares" : 0, // != undefined
"callCount" : 0 // != undefined
}],
[{
}
],[
{
"name" : "Supportability/Events/TransactionError/Seen" // != undefined
},{
"total" : 0, // != undefined
Expand All @@ -222,8 +244,9 @@ test("merging metrics and errors after a 503", function (t) {
"max" : 0, // != undefined
"sumOfSquares" : 0, // != undefined
"callCount" : 1 // != undefined
}],
[{
}
],[
{
"name" : "Supportability/Events/TransactionError/Sent" // != undefined
},{
"total" : 0, // != undefined
Expand Down
2 changes: 0 additions & 2 deletions test/integration/core/crypto.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ test('randomBytes', function(t) {
t.notOk(err, 'should not error')
t.ok(key.length, 32)
verifySegments(t, agent, 'crypto.randomBytes')
t.end()
})
})
})
Expand All @@ -46,7 +45,6 @@ test('pseudoRandomBytes', function(t) {
t.notOk(err, 'should not error')
t.ok(key.length, 32)
verifySegments(t, agent, 'crypto.pseudoRandomBytes')
t.end()
})
})
})
Expand Down
29 changes: 16 additions & 13 deletions test/integration/core/fs.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,23 +445,26 @@ test('realpath', function(t) {
t.equal(target, real, 'should point to the same file')

if (semver.satisfies(process.versions.node, '6.0.x - 6.3.x')) {
verifySegments(t, agent, NAMES.FS.PREFIX + 'realpath')
verifySegments(t, agent, NAMES.FS.PREFIX + 'realpath', afterVerify)
} else {
verifySegments(t, agent, NAMES.FS.PREFIX + 'realpath',
[NAMES.FS.PREFIX + 'lstat'])
[NAMES.FS.PREFIX + 'lstat'], afterVerify)
}

trans.end(function checkMetrics() {
var expectedMetrics = ['lstat', 'realpath']
// Node 6 changed implementation of fs.realpath()
if (semver.satisfies(process.versions.node, '>=6.0.0')) {
expectedMetrics = ['realpath']
}
t.ok(
checkMetric(expectedMetrics, agent, trans.name),
'metric should exist after transaction end'
)
})
function afterVerify() {
trans.end(function checkMetrics() {
var expectedMetrics = ['lstat', 'realpath']
// Node 6 changed implementation of fs.realpath()
if (semver.satisfies(process.versions.node, '>=6.0.0')) {
expectedMetrics = ['realpath']
}
t.ok(
checkMetric(expectedMetrics, agent, trans.name),
'metric should exist after transaction end'
)
t.end()
})
}
})
})
})
Expand Down
Loading

0 comments on commit 0181a7b

Please sign in to comment.