-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TaskGroup doesnt work well with assertion libraries like assert and should #17
Comments
If you call done callback from next tick then it works: var TaskGroup = require('taskgroup').TaskGroup;
var Task = require('taskgroup').Task;
var assert = require('assert');
function toTest(a, next) {
var tasks = new TaskGroup();
tasks.addTask('upper case', function(next) {
a = a.toUpperCase();
next();
});
tasks.done(function(err) {
next(err, a);
}).run();
}
function toTest2(a, next) {
var tasks = new TaskGroup();
tasks.addTask('upper case', function(next) {
a = a.toUpperCase();
next();
});
tasks.done(function(err) {
setTimeout(function() {
next(err, a);
});
}).run();
}
function toTestWithoutTaskGroup(a, next) {
a = a.toUpperCase();
setTimeout(function() {
next(null, a);
}, 10);
}
toTest("abc", function(err, r) {
assert.equal(r, "lmn");
});
toTest2("abc", function(err, r) {
assert.equal(r, "pqr");
});
toTestWithoutTaskGroup("abc", function(err, r) {
assert.equal(r, "efg");
}); In above code assertion will report failure in toTest2 and toTestWithoutTaskGroup |
If anyone else is facing this issue, here is a quick fix. Just add this code before your tests: var TaskGroup = require('taskgroup').TaskGroup;
var Task = require('taskgroup').Task;
if(!TaskGroup.prototype.oldOnceDone) {
TaskGroup.prototype.oldOnceDone = TaskGroup.prototype.onceDone;
TaskGroup.prototype.onceDone = function(next) {
if(typeof(next) != 'function') {
return this;
};
return this.oldOnceDone(function() {
var args = Array.prototype.slice.call(arguments);
process.nextTick(function() {
next.apply(null, args);
});
});
};
} |
Thanks for the report. Definitely a bug. I wonder if that quick fix will still pass the TaskGroup test suite? |
I forked and updated whenDone, onceDone: kksharma1618@dd079a7 Test failed: https://www.dropbox.com/s/z2o8v6wp7nuq59w/Screenshot%202015-02-01%2018.46.13.png?dl=0 |
Yeah, so nextTick won't work. I wonder if it is due to the |
Well, I think that test failed because completion state of task group wasnt set properly when assert was done. Results were same in both actual and expected values, only difference was completed tasks count. |
Running your original code, this is the output I get:
|
Is that what you got? |
Can I see code for issue17.js? |
Seems you've updated it, will try with your update. |
Distilled down to: var TaskGroup = require('./').TaskGroup
var Task = require('./').Task
var assert = require('assert')
var tasks = new TaskGroup()
tasks.addTask('test', function(complete) {
console.log('hello world')
complete()
});
tasks.done(function(err) {
throw new Error('goodbye world')
}).run() |
yep. goodbye world error shouldnt be suppressed. ideal solution will be, like you said, to fix the domain. call done listeners outside of it. |
Seems domain doesn't have anything to do with it, disabling it did nothing. |
Weird output with:
|
Found the cause, working on a fix. Leave it with me :-) 👍 |
great. thanks :) |
Got a fix locally, but I'm really tired and it has a minor breaking change. Will sleep on it and release tomorrow. |
So the issue was actually being called by the try...catch that was used, AS well as the domain - hence why disabling domains still caused the issue. This is also why the nextTick workaround worked, as it killed the scope. I've fixed it by removing the try...catch and limiting the scope of the domain to just where it is needed as well as manually exiting it upon task method completion. Fix will be in v4.1.0. Releasing now. |
Will add documentation in next commit
Released. |
- Reintroduced `try...catch` for Node v0.8 and browser environments with a workaround to prevent error suppression - Thanks to [kksharma1618](https://github.com/kksharma1618) for [issue - Closes [issue #18](#17) - You can now ignore all the warnings from the v4.1.0 changelog as the behaviour is more or less the same as v4.0.5 but with added improvements
Ended up releasing v4.2.0 that has try catch still in it, but uses your next tick idea :-) As it was needed for node 0.8 and browser compat |
Thanks for the fix. Just updated and tried again. Works. Cool library btw, I was using async before this. Just switched to taskgroup in this project. I really like how you implemented taskgroup. |
just got latest from master and running the tests with node 0.12.0 give this error
|
@pflannery I'll check it out, strange as I tested it with 0.11 and iojs and worked fine |
Mainly because it suppresses errors from callback.
Code:
In above code, only the second assert (toTestWithoutTaskGroup) will report the failure. First assert will still throw the error but TaskGroup suppresses that. Maybe it shouldnt suppress errors in final callback?
The text was updated successfully, but these errors were encountered: