summaryrefslogtreecommitdiff
path: root/mocha_test
diff options
context:
space:
mode:
authorAugusto Franzoia <ajfranzoia@gmail.com>2016-03-07 00:57:22 -0300
committerAugusto Franzoia <ajfranzoia@gmail.com>2016-03-07 00:57:22 -0300
commit0d87dd08374f95df0ba1449cdbb4bc5db320dee7 (patch)
tree87e1fb4e325831d55d7ce3490201ec3ef9720a24 /mocha_test
parentf75579366c69940dad5d4ee0b6b7070485701481 (diff)
downloadasync-0d87dd08374f95df0ba1449cdbb4bc5db320dee7.tar.gz
Support function timeout via async.timeout wrapper
Diffstat (limited to 'mocha_test')
-rw-r--r--mocha_test/timeout.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/mocha_test/timeout.js b/mocha_test/timeout.js
new file mode 100644
index 0000000..8355eb6
--- /dev/null
+++ b/mocha_test/timeout.js
@@ -0,0 +1,48 @@
+var async = require('../lib');
+var expect = require('chai').expect;
+
+describe('timeout', function () {
+
+ it('timeout with series', function(done){
+ async.series([
+ async.timeout(function asyncFn(callback) {
+ setTimeout(function() {
+ callback(null, 'I didn\'t time out');
+ }, 50);
+ }, 200),
+ async.timeout(function asyncFn(callback) {
+ setTimeout(function() {
+ callback(null, 'I will time out');
+ }, 300);
+ }, 150)
+ ],
+ function(err, results) {
+ expect(err.message).to.equal('Callback function timed out.');
+ expect(err.code).to.equal('ETIMEDOUT');
+ expect(results[0]).to.equal('I didn\'t time out');
+ done();
+ });
+ });
+
+ it('timeout with parallel', function(done){
+ async.parallel([
+ async.timeout(function asyncFn(callback) {
+ setTimeout(function() {
+ callback(null, 'I didn\'t time out');
+ }, 50);
+ }, 200),
+ async.timeout(function asyncFn(callback) {
+ setTimeout(function() {
+ callback(null, 'I will time out');
+ }, 300);
+ }, 150)
+ ],
+ function(err, results) {
+ expect(err.message).to.equal('Callback function timed out.');
+ expect(err.code).to.equal('ETIMEDOUT');
+ expect(results[0]).to.equal('I didn\'t time out');
+ done();
+ });
+ });
+
+});