Skip to content

Commit

Permalink
Merge pull request #671 from rjrodger/master
Browse files Browse the repository at this point in the history
bug fixes
  • Loading branch information
rjrodger committed Aug 10, 2017
2 parents e7d8424 + ac0084a commit b712694
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 46 deletions.
23 changes: 4 additions & 19 deletions lib/common.js
Expand Up @@ -541,16 +541,18 @@ exports.history = function history(opts) {
}

function History(opts) {
var self = this
opts = opts || {}

this._total = 0
this._list = []
this._map = {}

if (opts.prune) {
this._prunehist = []
this._prune_interval = setInterval(
this.prune.bind(this),
function() {
self.prune(Date.now())
},
opts.interval || 100
)
if (this._prune_interval.unref) {
Expand Down Expand Up @@ -582,53 +584,36 @@ History.prototype.place = function place(timelimit) {
var i = this._list.length
var s = 0
var e = i
//var c = 'u'

if (0 === this._list.length) {
return 0
}

do {
i = Math.floor((s + e) / 2)
//i = Math.ceil((s+e)/2)
//console.log('S ',i,s,e)

if (timelimit > this._list[i].timelimit) {
s = i + 1
i = s
//c = 's'
} else if (timelimit < this._list[i].timelimit) {
e = i
//i = e
//c = 'e'
} else {
i++
break
}

//console.log('E ',i,s,e,s<e,c)
} while (s < e)

return i
}

History.prototype.prune = function prune(timelimit) {
var startlen = this._list.length

var i = this.place(timelimit)
if (0 <= i && i <= this._list.length) {
for (var j = 0; j < i; j++) {
delete this._map[this._list[j].id]
}
this._list = this._list.slice(i)
}

var endlen = this._list.length

//console.log('PRUNE',startlen,endlen)
if (this._prunehist) {
this._prunehist.push([startlen, endlen])
}
}

History.prototype.get = function get(id) {
Expand Down
18 changes: 12 additions & 6 deletions lib/logging.js
Expand Up @@ -59,8 +59,10 @@ logging.preload = function() {

if ('test' === origspec || 'print' === origspec) {
var logb = [
time + '/' + seneca.id.substring(0, 2),
(data.kind || 'data') + (data.case ? '/' + data.case : '')
time + '/' + seneca.id.substring(0, 2) + '/' + seneca.tag,
(data.kind || 'data') +
(data.case ? '/' + data.case : '') +
(data.meta ? (data.meta.sync ? '/s' : '/a' ) : '')
]

if ('act' === data.kind) {
Expand Down Expand Up @@ -105,11 +107,15 @@ logging.preload = function() {
} else if ('notice' === data.kind) {
logb.push(data.notice)
} else if ('listen' === data.kind || 'client' === data.kind) {
logb.push(Util.inspect(data.options).replace(/\n/g, ' '))
//} else if (null == data.kind) {
// deliberately omit
var config = data.options && data.options[0]
logb.push([
config.type,
config.pin,
config.host,
_.isFunction(config.port) ? '' : config.port
].join(';'))
} else {
logb.push(Util.inspect(data).replace(/\n/g, ' '))
logb.push(Util.inspect(data).replace(/\n/g, ' ').substring(0, 88))
}

logstr = logb.join('\t')
Expand Down
4 changes: 4 additions & 0 deletions lib/transport.js
Expand Up @@ -17,6 +17,9 @@ var Common = require('./common')
// DO NOT COPY TO CREATE TRANSPORT PLUGINS
// USE THIS INSTEAD: [TODO github example]

// TODO: handle lists properly, without losing meta data


module.exports = function(seneca) {
seneca.add('role:transport,cmd:listen', action_listen)
seneca.add('role:transport,cmd:client', action_client)
Expand Down Expand Up @@ -77,6 +80,7 @@ function internalize_msg(seneca, msg) {
delete msg.meta$

msg.id$ = meta.id
msg.sync$ = meta.sync
msg.parents$ = meta.parents || []
msg.parents$.unshift(Common.make_trace_desc(meta))

Expand Down
18 changes: 8 additions & 10 deletions seneca.js
Expand Up @@ -945,15 +945,8 @@ function make_seneca(initial_options) {
var delegate = Object.create(self)
delegate.private$ = Object.create(self.private$)

var loc = new Error().stack
.split('\n')
.filter(function(line) {
return line.match(/mesh/) || line.match(/balance-client/)
})
.map(x => x.split('/').pop())

delegate.did =
(delegate.did ? delegate.did + '/' : '') + (didnid() + '~' + loc)
(delegate.did ? delegate.did + '/' : '') + didnid()

var strdesc
delegate.toString = function toString() {
Expand Down Expand Up @@ -1297,6 +1290,7 @@ intern.execute_action = function(
data.id = data.meta.id
data.result = []
data.timelimit = Date.now() + data.meta.timeout

private$.history.add(data)

if (opts.$.legacy.meta) {
Expand Down Expand Up @@ -1449,19 +1443,23 @@ intern.handle_inward_break = function(
intern.make_actmsg = function(origmsg) {
var actmsg = Object.assign({}, origmsg)

if (actmsg.id$) {
delete actmsg.id$
}

if (actmsg.caller$) {
delete actmsg.caller$
}

if (actmsg.meta$) {
delete actmsg.meta$
}

// backwards compatibility for Seneca 3.x transports
if (origmsg.transport$) {
actmsg.transport$ = origmsg.transport$
}

return actmsg
}

Expand Down
2 changes: 1 addition & 1 deletion test/actions.test.js
Expand Up @@ -42,7 +42,7 @@ describe('actions', function() {
})

it('cmd_close', function(fin) {
var si = Seneca({ log: 'silent' })
var si = Seneca().test(fin)

var log = []
si.on('close', function() {
Expand Down
26 changes: 19 additions & 7 deletions test/prior.test.js
Expand Up @@ -14,14 +14,26 @@ var expect = Code.expect
var testopts = { log: 'test' }

describe('prior', function() {
lab.beforeEach(function(done) {
process.removeAllListeners('SIGHUP')
process.removeAllListeners('SIGTERM')
process.removeAllListeners('SIGINT')
process.removeAllListeners('SIGBREAK')
done()
})

it('happy', function(fin) {
Seneca()
.test(fin)

.add('a:1', function a1(msg, reply) {
reply({x:msg.x})
})

.add('a:1', function a1p(msg, reply) {
msg.x = msg.x + 1
this.prior(msg, reply)
})

.act('a:1,x:2', function(ignore, out) {
expect(out.x).equal(3)
fin()
})
})

it('add-general-to-specific', function(done) {
Seneca(testopts)
.error(done)
Expand Down
15 changes: 12 additions & 3 deletions test/transport.test.js
Expand Up @@ -43,13 +43,18 @@ describe('transport', function() {
// TODO: test top level qaz:* : def and undef other pats

it('happy-nextgen', test_opts, function(fin) {
var s0 = Seneca({ id$: 's0', legacy: { transport: false } }).test(fin)
var c0 = Seneca({ id$: 'c0', timeout: 22222*tmx, legacy: { transport: false } }).test(fin)
var s0 = Seneca({ id$: 's0', legacy: { transport: false } })
.test(fin)
var c0 = Seneca({ id$: 'c0', timeout: 22222*tmx, legacy: { transport: false } })
.test(fin)

s0
.add('a:1', function a1(msg, reply, meta) {
reply({ x: msg.x })
})
.add('b:1', function a1(msg, reply, meta) {
reply([1,2,3])
})
.listen(62010)
.ready(function() {
c0.client(62010)
Expand All @@ -61,7 +66,11 @@ describe('transport', function() {
expect(meta.pattern).equals('')
expect(meta.trace[0].desc[0]).equals('a:1')

s0.close(c0.close.bind(c0, fin))
c0.act('b:1', function(ignore, out, meta) {
expect(out).equals([1,2,3])

s0.close(c0.close.bind(c0, fin))
})
})
})
})
Expand Down

0 comments on commit b712694

Please sign in to comment.