-
Notifications
You must be signed in to change notification settings - Fork 13
/
test.js
55 lines (45 loc) · 1.15 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
lib = require('./tests/lib.js');
var sh = require('child_process'),
fs = require('fs'),
net = require('net');
var master, slave, testServer, currTest;
var tested = 0,
failed = 0;
function init() {
master = sh.spawn('node', ['index.js', '--test', '--master']);
console.log('Started master ...');
slave = sh.spawn('node', ['index.js', '--test', '--slave', 'test-slave']);
console.log('Started slave ...');
testServer = net.createServer(testHandler);
testServer.listen(2359);
}
function testHandler(socket) {
var data = '';
socket.on('data', function(buf) {
data += buf;
});
socket.on('end', function() {
tested++;
if (!currTest.checkResponse(data))
failed++;
if (tested === tests.length)
shutdown();
else
runTests(tested);
});
};
function runTests(i) {
currTest = require('./tests/' + tests[i]);
currTest.runTest();
}
function shutdown() {
slave.kill();
master.kill();
process.exit(failed);
}
var tests = JSON.parse(fs.readFileSync('./tests/tests.json'));
init();
// wait for 1 second to ensure that master and slave servers are running
setTimeout(function() {
runTests(0);
}, 1000);