Skip to content

Commit

Permalink
Multiple setup/teardown run parallelly
Browse files Browse the repository at this point in the history
  • Loading branch information
5long committed Nov 5, 2010
1 parent b1fc895 commit 677e539
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doc/api.mkd
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/test_suite.js
Expand Up @@ -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)
}
Expand Down
15 changes: 15 additions & 0 deletions src/util.js
Expand Up @@ -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() {
Expand Down

0 comments on commit 677e539

Please sign in to comment.