<commit_before>var buster = require("buster");
var assert = buster.assert;
var refute = buster.refute;
var sinon = require("sinon");

var bCapServSessionQueue = require("../lib/session-queue");
var when = require("when");
var h = require("./test-helper");

var mockSession = function () {
    return buster.extend(buster.eventEmitter.create(), {
        started: sinon.spy(),
        loaded: sinon.spy(),
        ended: sinon.spy(),
        unloaded: sinon.spy(),
        aborted: sinon.spy(),
        capturedSlave: sinon.spy(),
        freedSlave: sinon.spy(),
        mockEnd: function () {
            this.emit("end");
        }
    });
}

buster.testCase("Session queue", {
    setUp: function () {
        this.sq = bCapServSessionQueue.create();
        this.sq.prepareSession = function (session) {
            var deferred = when.defer();
            deferred.resolve(session);
            return deferred.promise;
        };
        this.sq.teardownSession = function () {};
    },

    "adds slave when slave is prepared": function () {
        var slave = h.mockSlave();
        this.sq.addSlave(slave);
        assert.equals(this.sq.slaves.length, 0);

        slave.readyDeferred.resolve();
        assert.equals(this.sq.slaves.length, 1);
        assert.same(this.sq.slaves[0], slave);
    },

    "ignores slaves that fails prepare": function () {
        var slave = h.mockSlave();
        this.sq.addSlave(slave);
        slave.readyDeferred.reject();<commit_msg>Adding serialize to mock so logging doesn't fail tests.<commit_after>var buster = require("buster");
var assert = buster.assert;
var refute = buster.refute;
var sinon = require("sinon");

var bCapServSessionQueue = require("../lib/session-queue");
var when = require("when");
var h = require("./test-helper");

var mockSession = function () {
    return buster.extend(buster.eventEmitter.create(), {
        started: sinon.spy(),
        loaded: sinon.spy(),
        ended: sinon.spy(),
        unloaded: sinon.spy(),
        aborted: sinon.spy(),
        capturedSlave: sinon.spy(),
        freedSlave: sinon.spy(),
        serialize: function () {
            return {}
        },
        mockEnd: function () {
            this.emit("end");
        }
    });
}

buster.testCase("Session queue", {
    setUp: function () {
        this.sq = bCapServSessionQueue.create();
        this.sq.prepareSession = function (session) {
            var deferred = when.defer();
            deferred.resolve(session);
            return deferred.promise;
        };
        this.sq.teardownSession = function () {};
    },

    "adds slave when slave is prepared": function () {
        var slave = h.mockSlave();
        this.sq.addSlave(slave);
        assert.equals(this.sq.slaves.length, 0);

        slave.readyDeferred.resolve();
        assert.equals(this.sq.slaves.length, 1);
        assert.same(this.sq.slaves[0], slave);
    },

    "ignores slaves that fails prepare": function () {
        var slave = h.mockSlave();
        this.sq.addSlave(slave);
        slave.readyDeferred.reject();
{'fraction_non_alphanumeric': 0.1484375, 'fraction_numerical': 0.001953125, 'mean_word_length': 2.3732162458836443, 'pattern_counts': {'":': 4, '<': 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': '1975030', 'n_tokens_mistral': 944, 'n_tokens_neox': 932, 'n_words': 188}