[Pkg-javascript-commits] [node-async] 413/480: Add tests for queue idle() function
Jonas Smedegaard
js at moszumanska.debian.org
Fri May 2 08:58:47 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository node-async.
commit eeca6ef225fe956021c3de82e54876a5620c9fa7
Author: Craig Andrews <craig.andrews at bskyb.com>
Date: Fri Mar 28 15:43:14 2014 +0000
Add tests for queue idle() function
---
lib/async.js | 2 +-
test/test-async.js | 25 +++++++++++++++++++++++++
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/lib/async.js b/lib/async.js
index 2313bb1..64398b9 100755
--- a/lib/async.js
+++ b/lib/async.js
@@ -757,7 +757,7 @@
return workers;
},
idle: function() {
- return q.tasks.length == 0 && workers == 0;
+ return q.tasks.length + workers === 0;
}
};
return q;
diff --git a/test/test-async.js b/test/test-async.js
index b21b04f..f7eca6d 100755
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -2250,6 +2250,31 @@ exports['queue bulk task'] = function (test) {
}, 800);
};
+exports['queue idle'] = function(test) {
+ var q = async.queue(function (task, callback) {
+ // Queue is busy when workers are running
+ test.equal(q.idle(), false)
+ callback();
+ }, 1);
+
+ // Queue is idle before anything added
+ test.equal(q.idle(), true)
+
+ q.unshift(4);
+ q.unshift(3);
+ q.unshift(2);
+ q.unshift(1);
+
+ // Queue is busy when tasks added
+ test.equal(q.idle(), false)
+
+ q.drain = function() {
+ // Queue is idle after drain
+ test.equal(q.idle(), true);
+ test.done();
+ }
+}
+
exports['cargo'] = function (test) {
var call_order = [],
delays = [160, 160, 80];
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-async.git
More information about the Pkg-javascript-commits
mailing list