summaryrefslogtreecommitdiff
path: root/mocha_test
diff options
context:
space:
mode:
authorAlex Early <alexander.early@gmail.com>2017-05-21 20:05:14 -0700
committerGitHub <noreply@github.com>2017-05-21 20:05:14 -0700
commitb4c80c030124570823cfe4f0facd72720ff5033c (patch)
tree112cf615065c37d848672f75b74bc6f9cb578b2f /mocha_test
parent21ab91aa125f185f24749260a5a612a8ebc2735a (diff)
parent4f6ece185428b16c248ecb994b6d8f5849e46c83 (diff)
downloadasync-b4c80c030124570823cfe4f0facd72720ff5033c.tar.gz
Merge pull request #1419 from caolan/timeout-fix
Allow functions wrapped in `timeout` to be called multiple times (fixes #1418)
Diffstat (limited to 'mocha_test')
-rw-r--r--mocha_test/timeout.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/mocha_test/timeout.js b/mocha_test/timeout.js
index be41283..cd4a751 100644
--- a/mocha_test/timeout.js
+++ b/mocha_test/timeout.js
@@ -69,4 +69,40 @@ describe('timeout', function () {
done();
});
});
+
+ it('timeout with multiple calls (#1418)', function(done) {
+ var timeout = async.timeout(function asyncFn(n, callback) {
+ if (n < 1) {
+ setTimeout(function() {
+ callback(null, 'I will time out');
+ }, 75);
+ } else {
+ async.setImmediate(function() {
+ callback(null, 'I didn\'t time out');
+ })
+ }
+ }, 50);
+
+ async.series([
+ function(cb) {
+ timeout(0, function(err, result) {
+ expect(err.message).to.equal('Callback function "asyncFn" timed out.');
+ expect(err.code).to.equal('ETIMEDOUT');
+ expect(err.info).to.equal(undefined);
+ expect(result).to.equal(undefined);
+ cb();
+ });
+ },
+ function(cb) {
+ timeout(1, function(err, result) {
+ expect(err).to.equal(null);
+ expect(result).to.equal('I didn\'t time out');
+ cb();
+ });
+ }
+ ], function(err) {
+ expect(err).to.equal(null);
+ done();
+ });
+ })
});