Skip to content

Instantly share code, notes, and snippets.

@bobzoller
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobzoller/fb0502ee49a016b7b606 to your computer and use it in GitHub Desktop.
Save bobzoller/fb0502ee49a016b7b606 to your computer and use it in GitHub Desktop.
test case for new relic transaction issues w/node-fibers
exports.config = {
app_name : ['New Relic Hunter'],
license_key : 'abc',
logging : {
level : 'info'
}
};
{
"name": "new-relic-hunter",
"version": "1.0.0",
"dependencies": {
"express": "*",
"fibers": "*",
"newrelic": "*"
}
}
process.env.TZ = process.env.TZ || 'UTC';
var agent = require('newrelic').agent;
var express = require('express');
var Fiber = require('fibers');
var Future = require('fibers/future');
var api = Future.wrap(function(cb) {
return setTimeout(cb, 3000);
});
var app = express();
var fiberMiddleware = function(req, res, next) {
return Fiber(function() {
return next();
}).run();
};
app.use(fiberMiddleware);
//app.all('/*', fiberMiddleware);
app.get('/one', function(req, res) {
var t;
console.log(req.method, req.url, (t = agent.getTransaction()) ? t.id : null);
api().wait();
res.status(200).end();
});
app.get('/two', function(req, res) {
var t;
console.log(req.method, req.url, (t = agent.getTransaction()) ? t.id : null);
api().wait();
res.status(200).end();
});
var server = app.listen(process.env.PORT || 3000, function(err) {
if (err) {
console.error(err);
process.exit(1);
} else {
console.log('express server listening at http://%s:%s/', server.address().address, server.address().port);
}
});
#!/bin/sh
if [ "$PORT" == "" ]; then
PORT=3000
fi
PORT=$PORT node server.js &
SERVER_PID=$!
sleep 5
curl -sS http://localhost:$PORT/one &
CURL_PID_1=$!
sleep 1
curl -sS http://localhost:$PORT/two &
CURL_PID_2=$!
wait $CURL_PID_1 $CURL_PID_2
sleep 2
kill $SERVER_PID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment