summaryrefslogtreecommitdiff
path: root/mocha_test/timeout.js
diff options
context:
space:
mode:
Diffstat (limited to 'mocha_test/timeout.js')
-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();
+ });
+ });
+
+});