Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
Express patient app WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
LewisJEllis committed Mar 24, 2017
1 parent 8df74a4 commit 48390d3
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 0 deletions.
115 changes: 115 additions & 0 deletions test/manual/express-patient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
'use strict';

// make console log not print so when we hammer the console log endpoint we don't flood the terminal
console.log = function () {};

var Raven = require('../../');
var sentryDsn = 'https://523d0dad9d3f4632b0ead708edc84399:2f37f2629851455f9df44d48cfc23dc1@app.getsentry.com/93926';
Raven.config(sentryDsn, {
autoBreadcrumbs: true
}).install();

var util = require('util');
var http = require('http');
var nock = require('nock');


// eslint-disable-line no-unused-vars
var sentryScope = nock('https://app.getsentry.com')
.filteringRequestBody(/.*/, '*')
.post('/api/93926/store/', '*')
.reply(200, 'OK');

var memwatch = require('memwatch-next');
memwatch.on('stats', function (stats) {
process._rawDebug(util.format('gc #%d: min %d, max %d, est base %d, curr base %d',
stats.num_full_gc, stats.min, stats.max, stats.estimated_base, stats.current_base
));
});

var express = require('express');
var app = express();

var hitBefore = {};

app.use(Raven.requestHandler());

app.use(function (req, res, next) {
if (!hitBefore[req.url]) {
hitBefore[req.url] = true;
process._rawDebug('hit ' + req.url + ' for first time');
}
next();
});

app.get('/context/basic', function (req, res, next) {
Raven.setContext({
extra: {
example: 'hey look we set some example context data yay',
}
});
res.textToSend = 'hello there! we set some stuff to the context';
next();
});

app.get('/breadcrumbs/capture', function (req, res, next) {
Raven.captureBreadcrumb({
message: 'Captured example breadcrumb',
category: 'log',
data: {
example: 'hey look we captured this example breadcrumb yay'
}
});
res.textToSend = 'hello there! we captured an example breadcrumb';
next();
});

app.get('/breadcrumbs/auto/console', function (req, res, next) {
console.log('hello there! i am printing to the console!');
res.textToSend = 'hello there! we printed to the console';
next();
});

app.get('/breadcrumbs/auto/http', function (req, res, next) {
var scope = nock('http://www.example.com')
.get('/hello')
.reply(200, 'hello world');

http.get('http://example.com/hello', function (nockRes) {
scope.done();
res.textToSend = 'hello there! we got hello world from example.com';
next();
}).on('error', next);
});

app.get('/hello', function (req, res, next) {
res.textToSend = 'hello!';
next();
});

app.get('/gc', function (req, res, next) {
memwatch.gc();
res.textToSend = 'collected garbage';
next();
});

app.use(function (req, res, next) {
if (req.query.doError) {
return next(new Error(res.textToSend));
}
return res.send(res.textToSend);
});

app.use(Raven.errorHandler());

app.use(function (err, req, res, next) {
// todo probably comment out this rawDebug
// process._rawDebug('got an error');
// console.error(err);
return res.status(500).send('oh no there was an error: ' + err.message);
});

app.listen(3000, function () {
process._rawDebug('patient is waiting to be poked on port 3000');
memwatch.gc();
});
22 changes: 22 additions & 0 deletions test/manual/poke-patient.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
ab -c 5 -n 10000 localhost:3000/hello
curl localhost:3000/gc
ab -c 5 -n 10000 localhost:3000/context/basic
curl localhost:3000/gc
ab -c 5 -n 10000 localhost:3000/breadcrumbs/capture
curl localhost:3000/gc
ab -c 5 -n 10000 localhost:3000/breadcrumbs/auto/console
curl localhost:3000/gc
ab -c 5 -n 10000 localhost:3000/breadcrumbs/auto/http
curl localhost:3000/gc

ab -c 5 -n 10000 localhost:3000/hello?doError=true
curl localhost:3000/gc
ab -c 5 -n 10000 localhost:3000/context/basic?doError=true
curl localhost:3000/gc
ab -c 5 -n 10000 localhost:3000/breadcrumbs/capture?doError=true
curl localhost:3000/gc
ab -c 5 -n 10000 localhost:3000/breadcrumbs/auto/console?doError=true
curl localhost:3000/gc
ab -c 5 -n 10000 localhost:3000/breadcrumbs/auto/http?doError=true
curl localhost:3000/gc

0 comments on commit 48390d3

Please sign in to comment.