Browse files

Multiple setup/teardown run parallelly

  • Loading branch information...
1 parent b1fc895 commit 677e5390f9c613b291f6affef48acdf96789cfc7 @5long committed Nov 5, 2010
Showing with 19 additions and 2 deletions.
  1. +2 −0 doc/api.mkd
  2. +2 −2 src/test_suite.js
  3. +15 −0 src/util.js
View
2 doc/api.mkd
@@ -92,6 +92,8 @@ Example:
Needless to say.
+Note that all setup and teardown functions are run parallelly.
+
### suiteMonad.test(desc, action)
Add a test to the suite. Tests always run after all the setups finish.
View
4 src/test_suite.js
@@ -40,12 +40,12 @@ util.merge(TestSuite.prototype, {
)
}
, _doSetup: function(fixture, cb) {
- async.map(this._setupQueue, function(fn) {
+ async.paraMap(this._setupQueue, function(fn) {
fn(fixture, this)
}, cb)
}
, _doTeardown: function(fixture, cb) {
- async.map(this._teardownQueue, function(fn) {
+ async.paraMap(this._teardownQueue, function(fn) {
fn(fixture, this)
}, cb)
}
View
15 src/util.js
@@ -45,6 +45,21 @@ util.async = {
var array = array.slice()
defer(mapIter, [array, action, [], cb])
}
+, paraMap: function(array, action, cb) {
+ if (!array.length) return cb && cb(null, [])
+ var results = []
+ , latestErr = null
+ , num = 0
+ array.map(function(val, key) {
+ num++
+ function innerCallback(err, data) {
+ latestErr = err
+ results[key] = data || err
+ if (!--num) cb && cb(latestErr, results)
+ }
+ action.call(innerCallback, val)
+ })
+ }
, chain: function() {
var actions = makeArray(arguments)
process.nextTick(function() {

0 comments on commit 677e539

Please sign in to comment.