Sha256: 0745728809334114c4b8706ef45b31fd7a3d9ce323f31ae866f3f6f79f95283e

Contents?: true

Size: 1.19 KB

Versions: 4

Compression:

Stored size: 1.19 KB

Contents

var async = require('async');
var Throttle = require('../index.js').Throttle;
var ThrottleGroup = require('../index.js').ThrottleGroup;

var sendStr = (function() {
    var s = '0123456789xyzXYZ?!\0åéîõü$£€*<>'; // 30 characters
    for (var i = 0, str = ''; i < 1000; i++)
        str += s;
    return str; // 30K characters
})();

var opts = {rate: 100000}; // 100 KiB/s

var testSendRecv = function(t, cb) {
    var recvStr = '';
    t.on('data', function(chunk) {
        recvStr += chunk;
    });
    t.on('end', function() {
        cb(sendStr == recvStr);
    });
    t.write(sendStr, function() {
        t.end();
    });
};

exports.testThrottle = function(test) {
    var t = new Throttle(opts);

    test.expect(1);
    testSendRecv(t, function(ok) {
        test.ok(ok, "received string should equal sent string");
        test.done();
    });
};

exports.testGroupThrottle = function(test) {
    var tg = new ThrottleGroup(opts);

    test.expect(3);
    async.each([1, 2, 3], function(i, done) {
        testSendRecv(tg.throttle(), function(ok) {
            test.ok(ok, "received string should equal sent string");
            done();
        });
    }, function() {
        test.done();
    });
};

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
ilog-0.4.1 node_modules/stream-throttle/test/throttle_test.js
ilog-0.4.0 node_modules/stream-throttle/test/throttle_test.js
ilog-0.3.3 node_modules/stream-throttle/test/throttle_test.js
blackboard-3.1.9 lib/site_template/node_modules/stream-throttle/test/throttle_test.js