<commit_before>var ipc = require('node-ipc');
var spawn = require('child_process').spawn;
var expect = require('chai').expect;

ipc.config.silent = true;

describe('Beacon\'s Process', function() {

    //this.timeout(10000);

    var beacon_process = spawn('node', ['./lib/beacon.js']);
    var beacon_process_exit = new Promise(function(resolve, reject) {
        beacon_process.on('exit', function() {resolve();});
    });

    it('responds to \'PROBE:MSG\'', function(done) {
        setTimeout(function() {
            ipc.connectTo('klyng_beacon', function() {
                ipc.of.klyng_beacon.emit('PROBE:MSG', {});
                ipc.of.klyng_beacon.on('ALIVE:MSG', function() {
                    ipc.disconnect('klyng_beacon');
                    done();
                });
            });
        }, 500);
    });

    it('responds with available to \'SIGNAL:RUN\' message', function(done) {
        ipc.connectTo('klyng_beacon', function() {
            ipc.of.klyng_beacon.emit('SIGNAL:RUN', {job_specs: {size: 1, app: './tests/fixtures/beacon/runner-fake-job.js'}});
            ipc.of.klyng_beacon.on('SIGNAL:CONFIRM', function(msg) {
                expect(msg.status).to.equal('available');
                ipc.disconnect('klyng_beacon');
                done();
            });
        });
    });

    it('responds with busy to second \'SIGNAL:RUN\' message', function(done) {
        ipc.connectTo('klyng_beacon', function() {
            ipc.of.klyng_beacon.emit('SIGNAL:RUN', {job_specs: {size: 1, app: './tests/fixtures/beacon/runner-fake-job.js'}});
            ipc.of.klyng_beacon.on('SIGNAL:CONFIRM', function(msg) {
                ipc.disconnect('klyng_beacon');
                expect(msg.status).to.equal('busy');
                done();
            });
        });
    });

    it('responds to a \'SIGNAL:DONE\' message', function(done) {
        ipc.connectTo('klyng_beacon', function() {
            ipc.of.klyng_beacon.emit('SIGNAL:DONE', {});
            ipc.of.klyng_beacon.socket.on('end', function() {
                ipc.disconnect('klyng_beacon');
                done();
            });
        });
    });

    it('responds to a \'STOP:MSG\'', function(done) {
        ipc.connectTo('klyng_beacon', function() {
            ipc.of.klyng_beacon.emit('STOP:MSG', {});
            var socket_close = new Promise(function(resolve, reject) {
                ipc.of.klyng_beacon.socket.on('end', function() {
                    ipc.disconnect('klyng_beacon');
                    resolve();
                });
            });

            Promise.all([socket_close, beacon_process_exit]).then(function(){
                done();
            });
        });
    });

});<commit_msg>adapted tests to the new error handeling changes<commit_after>var ipc = require('node-ipc');
var spawn = require('child_process').spawn;
var expect = require('chai').expect;

ipc.config.silent = true;

describe('Beacon\'s Process', function() {

    this.timeout(6000);

    var beacon_process = spawn('node', ['./lib/beacon.js']);
    var beacon_process_exit = new Promise(function(resolve, reject) {
        beacon_process.on('exit', function() {resolve();});
    });

    it('responds with available to \'SIGNAL:RUN\' message', function(done) {
        ipc.connectTo('klyng_beacon', function() {
            ipc.of.klyng_beacon.on('connect', function() {
                ipc.of.klyng_beacon.emit('SIGNAL:RUN', {job_specs: {size: 1, app: './tests/fixtures/beacon/fake-job.js'}});
                ipc.of.klyng_beacon.on('SIGNAL:CONFIRM', function(msg) {
                    expect(msg.status).to.equal('available');
                    ipc.disconnect('klyng_beacon');
                    done();
                });
            })
        });
    });

    it('responds with busy to second \'SIGNAL:RUN\' message', function(done) {
        ipc.connectTo('klyng_beacon', function() {
            ipc.of.klyng_beacon.on('connect', function() {
                ipc.of.klyng_beacon.emit('SIGNAL:RUN', {job_specs: {size: 1, app: './tests/fixtures/beacon/runner-fake-job.js'}});
                ipc.of.klyng_beacon.on('SIGNAL:CONFIRM', function(msg) {
                    ipc.disconnect('klyng_beacon');
                    expect(msg.status).to.equal('busy');
                    done();
                });
            })
        });
    });

    it('responds to a \'SIGNAL:DONE\' message', function(done) {
        ipc.connectTo('klyng_beacon', function() {
            ipc.of.klyng_beacon.on('connect', function() {
                ipc.of.klyng_beacon.emit('SIGNAL:DONE', {});
                ipc.of.klyng_beacon.socket.on('end', function() {
                    ipc.disconnect('klyng_beacon');
                    done();
                });
            });
        });
    });

    it('responds to a \'STOP:MSG\'', function(done) {
        ipc.connectTo('klyng_beacon', function() {
            ipc.of.klyng_beacon.on('connect', function() {
                ipc.of.klyng_beacon.emit('STOP:MSG', {});
                var socket_close = new Promise(function(resolve, reject) {
                    ipc.of.klyng_beacon.socket.on('end', function() {
                        ipc.disconnect('klyng_beacon');
                        resolve();
                    });
                });

                Promise.all([socket_close, beacon_process_exit]).then(function(){
                    done();
                });
            });
        });
    });

});
{'fraction_non_alphanumeric': 0.16943582253058243, 'fraction_numerical': 0.002921307285010042, 'mean_word_length': 1.9231590181430096, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '402025', 'n_tokens_mistral': 1797, 'n_tokens_neox': 1707, 'n_words': 230}