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

Commit

Permalink
Use child_process to have fresh express process for each test
Browse files Browse the repository at this point in the history
  • Loading branch information
LewisJEllis committed Mar 25, 2017
1 parent 6d24ffd commit 8458993
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 29 deletions.
30 changes: 22 additions & 8 deletions test/manual/express-patient.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
console.log = function () {};

var Raven = require('../../');
var sentryDsn = 'https://523d0dad9d3f4632b0ead708edc84399:2f37f2629851455f9df44d48cfc23dc1@app.getsentry.com/93926';

var sentryDsn = 'https://public:private@app.getsentry.com/269';
Raven.config(sentryDsn, {
autoBreadcrumbs: true
}).install();
Expand All @@ -13,11 +14,10 @@ var util = require('util');
var http = require('http');
var nock = require('nock');


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

var memwatch = require('memwatch-next');
Expand Down Expand Up @@ -75,7 +75,7 @@ app.get('/breadcrumbs/auto/http', function (req, res, next) {
.get('/hello')
.reply(200, 'hello world');

http.get('http://example.com/hello', function (nockRes) {
http.get('http://www.example.com/hello', function (nockRes) {
scope.done();
res.textToSend = 'hello there! we got hello world from example.com';
next();
Expand All @@ -93,6 +93,23 @@ app.get('/gc', function (req, res, next) {
next();
});

app.get('/shutdown', function (req, res, next) {
setTimeout(function () {
server.close(function () {
process.exit();
});
}, 100);
return res.send('shutting down');
});

app.get('/capture', function (req, res, next) {
for (var i = 0; i < 1000; ++i) {
Raven.captureException(new Error('oh no an exception to capture'));
}
res.textToSend = 'capturing an exception!';
next();
});

app.use(function (req, res, next) {
if (req.query.doError) {
return next(new Error(res.textToSend));
Expand All @@ -103,13 +120,10 @@ app.use(function (req, res, next) {
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 () {
var server = app.listen(3000, function () {
process._rawDebug('patient is waiting to be poked on port 3000');
memwatch.gc();
});
16 changes: 16 additions & 0 deletions test/manual/manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';
var child_process = require('child_process');

var child;
function startChild() {
console.log('starting child');
child = child_process.spawn('node', ['express-patient.js']);
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);
child.on('exit', function () {
console.log('child exited');
startChild();
});
}

startChild();
59 changes: 38 additions & 21 deletions test/manual/poke-patient.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
#!/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
gc_restart() {
sleep 1
curl localhost:3000/gc
sleep 1
curl localhost:3000/shutdown
sleep 1
}

ab -c 5 -n 5000 localhost:3000/hello
gc_restart

ab -c 5 -n 5000 localhost:3000/context/basic
gc_restart

ab -c 5 -n 5000 localhost:3000/breadcrumbs/capture
gc_restart

ab -c 5 -n 5000 localhost:3000/breadcrumbs/auto/console
gc_restart

ab -c 5 -n 5000 localhost:3000/breadcrumbs/auto/http
gc_restart


ab -c 5 -n 5000 localhost:3000/hello?doError=true
gc_restart

ab -c 5 -n 5000 localhost:3000/context/basic?doError=true
gc_restart

ab -c 5 -n 5000 localhost:3000/breadcrumbs/capture?doError=true
gc_restart

ab -c 5 -n 5000 localhost:3000/breadcrumbs/auto/console?doError=true
gc_restart

ab -c 5 -n 5000 localhost:3000/breadcrumbs/auto/http?doError=true
gc_restart

0 comments on commit 8458993

Please sign in to comment.