Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

concurrencyLevel check

  • Loading branch information...
commit 6a2d1df2060731f08692edfecdc6faea4b9f2719 1 parent 5532606
Kilian Ciuffolo authored

Showing 2 changed files with 60 additions and 0 deletions. Show diff stats Hide diff stats

  1. +12 0 lib/fnqueue.js
  2. +48 0 test/fnqueue-test.js
12 lib/fnqueue.js
@@ -8,6 +8,18 @@ function FnQueue(tasks, callback, concurrecyLevel, isStopped) {
8 8 this.concurrecyLevel = concurrecyLevel || 'auto';
9 9 this.runningNb = 0;
10 10 this.loadDependencies();
  11 +
  12 + if (typeof this.concurrecyLevel !== 'string' && typeof this.concurrecyLevel !== 'number') {
  13 + this.onTaskComplete(null, new Error('Invalid concurrecyLevel: ' + typeof this.concurrecyLevel + ', must be a Number or \'auto\''));
  14 + return;
  15 + } else if (typeof this.concurrecyLevel === 'number' && this.concurrecyLevel < 1) {
  16 + this.onTaskComplete(null, new Error('Invalid concurrecyLevel: ' + this.concurrecyLevel + ' < 1'));
  17 + return;
  18 + } else if (typeof this.concurrecyLevel === 'string' && this.concurrecyLevel !== 'auto') {
  19 + this.onTaskComplete(null, new Error('Invalid concurrecyLevel: ' + this.concurrecyLevel + ' < 1'));
  20 + return;
  21 + }
  22 +
11 23 !isStopped && this.callNextFunction();
12 24 }
13 25
48 test/fnqueue-test.js
@@ -183,6 +183,54 @@ vows.describe('FnQueue').addBatch({
183 183 });
184 184 }
185 185 },
  186 + 'FnQueue with a wrong concurrency level (< 0)': {
  187 + topic: function () {
  188 + new FnQueue({
  189 + fn1: function (callback) {
  190 + setTimeout(callback.bind(null, null, 'fn1'), 500);
  191 + },
  192 + fn2: function (callback) {
  193 + setTimeout(callback.bind(null, null, 'fn2'), 500);
  194 + },
  195 + fn3: function (callback) {
  196 + setTimeout(callback.bind(null, null, undefined), 500);
  197 + },
  198 + fn4: function (callback) {
  199 + setTimeout(callback.bind(null, null, false), 500);
  200 + }
  201 + }, this.callback, -5);
  202 + },
  203 + 'should call the main callback with an error': function (err, data) {
  204 + assert.isNotNull(err);
  205 + },
  206 + 'error should match the "Invalid Function in list..." messgae': function (err, data) {
  207 + assert.match(err.message, /^Invalid concurrecyLevel/);
  208 + }
  209 + },
  210 + 'FnQueue with a wrong concurrency level (!== \'auto\')': {
  211 + topic: function () {
  212 + new FnQueue({
  213 + fn1: function (callback) {
  214 + setTimeout(callback.bind(null, null, 'fn1'), 500);
  215 + },
  216 + fn2: function (callback) {
  217 + setTimeout(callback.bind(null, null, 'fn2'), 500);
  218 + },
  219 + fn3: function (callback) {
  220 + setTimeout(callback.bind(null, null, undefined), 500);
  221 + },
  222 + fn4: function (callback) {
  223 + setTimeout(callback.bind(null, null, false), 500);
  224 + }
  225 + }, this.callback, 'wrong!');
  226 + },
  227 + 'should call the main callback with an error': function (err, data) {
  228 + assert.isNotNull(err);
  229 + },
  230 + 'error should match the "Invalid Function in list..." messgae': function (err, data) {
  231 + assert.match(err.message, /^Invalid concurrecyLevel/);
  232 + }
  233 + },
186 234 'FnQueue with some error throwing function': {
187 235 topic: function () {
188 236 new FnQueue({

0 comments on commit 6a2d1df

Please sign in to comment.
Something went wrong with that request. Please try again.