Skip to content

Commit

Permalink
fix pruning bug
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrodger committed Aug 6, 2017
1 parent 1904aa1 commit 1d3b0be
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 21 deletions.
15 changes: 4 additions & 11 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 @@ -613,22 +615,13 @@ History.prototype.place = function place(timelimit) {
}

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
2 changes: 2 additions & 0 deletions lib/inward.js
Expand Up @@ -182,6 +182,8 @@ function inward_act_cache(ctxt, data) {
var actid = meta.id
var private$ = ctxt.seneca.private$

// console.log(data.msg, meta)

if (actid != null && so.history.active) {
var actdetails = private$.history.get(actid)

Expand Down
3 changes: 3 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
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) {
console.log(out)
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 1d3b0be

Please sign in to comment.