Skip to content

Commit

Permalink
Clean up queue management, loads of debugging
Browse files Browse the repository at this point in the history
It'd be good to move the debugging into a function so that I can turn it
on and off with a NODE_DEBUG=tap env setting.

Spawn still isn't working, but child Tests are good with buffering and
parallelizing in the job pool.
  • Loading branch information
isaacs committed Jan 12, 2017
1 parent f5962e9 commit ea7ee51
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 44 deletions.
1 change: 0 additions & 1 deletion lib/asserts.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ exports.decorate = decorate

function decorate (t) {
t.addAssert('ok', 1, function (obj, message, extra) {
console.error('in ok', obj, message, extra)
message = message || 'expect truthy value'
if (obj) {
return this.pass(message, extra)
Expand Down
34 changes: 28 additions & 6 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,20 @@ function Base (options) {
if (this.skip || this.todo)
this.main = Base.prototype.main

Readable.apply(this)
Readable.apply(this, options)
this.ended = false
this.on('end', function () {
this.ended = true
})
}

Base.prototype.main = function (cb) {
this.finished = true
cb()
}

Base.prototype.online = function (line) {
this.push(this.indent + line)
console.error('LINE %s %j', this.name, line)
return this.push(this.indent + line)
}

Base.prototype.push = function (c, e) {
Expand All @@ -65,8 +69,7 @@ Base.prototype.push = function (c, e) {
this._readableState.sync = false
}

this.emit('line', c)

// console.error(this._readableState)
return Readable.prototype.push.call(this, c, e)
}

Expand All @@ -75,6 +78,7 @@ Base.prototype.onbail = function (reason) {
}

Base.prototype.oncomplete = function (results) {
console.error('ONCOMPLETE %j %j', this.name, results)
this.results = results
this.emit('end')
}
Expand All @@ -92,4 +96,22 @@ Base.prototype.setupParser = function (options) {
this.parser.on('complete', this.oncomplete.bind(this))
}

Base.prototype._read = function (n, cb) {}
Base.prototype._read = function (n) {
// this.emit('readable')
// console.error('_read %j', this.name, arguments)
}

Base.prototype.inspect = function () {
return this.constructor.name + ' ' + util.inspect({
name: this.name,
jobs: this.jobs,
buffered: this.buffered,
pool: this.pool,
queue: this.queue,
subtests: this.subtests,
output: this.output,
skip: this.skip,
todo: this.todo,
ended: this.ended
})
}
8 changes: 6 additions & 2 deletions lib/spawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ var cp = require('child_process')
var spawn = cp.spawn

function Spawn (options) {
options = options || {}
if (!(this instanceof Spawn))
return new Spawn(options)

Base.call(this, options)
this.command = options.command
if (!this.command) {
Expand Down Expand Up @@ -75,8 +79,8 @@ Spawn.prototype.main = function (cb) {
Spawn.prototype.onprocclose = function (cb, code, signal) {
if (!code && !signal)
return cb()
this.exitCode = code
this.signal = signal
this.options.exitCode = code
this.options.signal = signal
var er = new Error('command failed: ' + this.name)
er.code = code
er.signal = signal
Expand Down
4 changes: 4 additions & 0 deletions lib/stdin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ util.inherits(Stdin, Base)
module.exports = Stdin

function Stdin (options) {
options = options || {}
if (!(this instanceof Stdin))
return new Stdin(options)

options.name = ownOr(options, 'name', '/dev/stdin')
Base.call(this, options)

Expand Down

0 comments on commit ea7ee51

Please sign in to comment.