diff --git a/bin/sinopia b/bin/sinopia index 11861f5db..6f0112dcb 100755 --- a/bin/sinopia +++ b/bin/sinopia @@ -63,3 +63,8 @@ if (hostport[0] == null) { server(config).listen(hostport[1], hostport[0]); console.log('Server is listening on http://%s:%s/', hostport[0], hostport[1]); +// undocumented stuff for tests +if (typeof(process.send) === 'function') { + process.send({sinopia_started: hostport}); +} + diff --git a/test/config.yaml b/test/config-1.yaml similarity index 92% rename from test/config.yaml rename to test/config-1.yaml index f08f45004..1e749752b 100644 --- a/test/config.yaml +++ b/test/config-1.yaml @@ -9,4 +9,4 @@ packages: allow_access: test allow_publish: test -listen: 55550 +listen: 55551 diff --git a/test/config-2.yaml b/test/config-2.yaml new file mode 100644 index 000000000..b3be4f856 --- /dev/null +++ b/test/config-2.yaml @@ -0,0 +1,12 @@ +storage: ./test-storage2 + +users: + test: + password: a94a8fe5ccb19ba61c4c0873d391e987982fbbd3 + +packages: + '*': + allow_access: test + allow_publish: test + +listen: 55552 diff --git a/test/dos/get-tarball.js b/test/dos/get-tarball.js index 882b40976..356a257d6 100755 --- a/test/dos/get-tarball.js +++ b/test/dos/get-tarball.js @@ -7,7 +7,7 @@ var readfile = require('fs').readFileSync; var binary = readfile('../fixtures/binary'); var count = 10000; -var server = new Server('http://localhost:55550/'); +var server = new Server('http://localhost:55551/'); async.series([ function(cb) { server.auth('test', 'test', function(res, body) { diff --git a/test/run.js b/test/run.js index 7cc5d2a1d..75b3d65d2 100755 --- a/test/run.js +++ b/test/run.js @@ -1,23 +1,33 @@ #!/usr/bin/env node +var fs = require('fs'); var async = require('async'); var assert = require('assert'); var rimraf = require('rimraf'); var Server = require('./lib/server'); +var fork = require('child_process').fork; var readfile = require('fs').readFileSync; +var forks = []; -var server = new Server('http://localhost:55550/'); +var server = new Server('http://localhost:55551/'); async.series([ function(cb) { - rimraf('./test-storage', cb); - }, - function(cb) { - process.argv = ['node', 'sinopia', '-c', './config.yaml']; - require('../bin/sinopia'); - cb(); - }, - function(cb) { - setTimeout(cb, 1000); + var count = 0; + function start(dir, conf) { + count++; + rimraf(dir, function() { + var f = fork('../bin/sinopia', ['-c', conf], {stdio: [null,null,null]}); + forks.push(f); + f.on('message', function(msg) { + if ('sinopia_started' in msg) { + if (!--count) cb(); + } + }); + }); + }; + + start('./test-storage', './config-1.yaml', cb); + start('./test-storage2', './config-2.yaml', cb); }, function(cb) { server.auth('test', 'test', function(res, body) { @@ -73,3 +83,12 @@ async.series([ process.exit(); }); +process.on('exit', function() { + if (forks[0]) forks[0].kill(); + if (forks[1]) forks[1].kill(); +}); + +process.on('uncaughtException', function() { + process.exit(1); +}); +