summaryrefslogtreecommitdiff
path: root/test/test-async.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/test-async.js')
-rwxr-xr-xtest/test-async.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/test-async.js b/test/test-async.js
index bd103bf..b4aef6c 100755
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -3825,3 +3825,49 @@ exports['asyncify'] = {
return promises;
}, {})
};
+
+exports['timeout'] = function (test) {
+ test.expect(3);
+
+ 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) {
+ test.ok(err.message === 'Callback function timed out.');
+ test.ok(err.code === 'ETIMEDOUT');
+ test.ok(results[0] === 'I didn\'t time out');
+ test.done();
+ });
+};
+
+exports['timeout with parallel'] = function (test) {
+ test.expect(3);
+
+ 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) {
+ test.ok(err.message === 'Callback function timed out.');
+ test.ok(err.code === 'ETIMEDOUT');
+ test.ok(results[0] === 'I didn\'t time out');
+ test.done();
+ });
+};