Skip to content

Commit

Permalink
improv: fix #58 agent queue
Browse files Browse the repository at this point in the history
  • Loading branch information
Eywek committed May 31, 2018
1 parent 215a118 commit f977096
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/transporters/AxonTransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ module.exports = class AxonTransport extends Transporter {
log('Trying to send data while not connected, buffering ...')

// remove last element if the queue is full
if (this.queue.size >= cst.PACKET_QUEUE_SIZE) {
this.queue.pop()
if (this.queue.length >= cst.PACKET_QUEUE_SIZE) {
this.queue.shift()
}
return this.queue.push({ channel: channel, data: data })
}
Expand Down
4 changes: 2 additions & 2 deletions src/transporters/WebsocketTransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ module.exports = class WebsocketTransport extends Transporter {
log('Trying to send data while not connected, buffering ...')

// remove last element if the queue is full
if (this.queue.size >= cst.PACKET_QUEUE_SIZE) {
this.queue.pop()
if (this.queue.length >= cst.PACKET_QUEUE_SIZE) {
this.queue.shift()
}
return this.queue.push({ channel: channel, data: data })
}
Expand Down
6 changes: 3 additions & 3 deletions test/units/InteractorClient.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ describe('InteractorClient', () => {
assert(config.secret_key === 'private')
assert(config.machine_name === 'machine')
assert(config.reverse_interact === true)
assert(config.info_node === 'info')
assert(config.info_node === 'https://info')
fs.writeFileSync = tmpWrite
fs.readFileSync = tmpRead
module.exports = fs
Expand All @@ -387,7 +387,7 @@ describe('InteractorClient', () => {
public_key: 'public',
secret_key: 'private',
machine_name: 'machine',
info_node: 'info',
info_node: 'https://info',
reverse_interact: 'lol',
version_management: {
active: false
Expand All @@ -403,7 +403,7 @@ describe('InteractorClient', () => {
assert(config.secret_key === 'private')
assert(config.machine_name === 'machine')
assert(config.reverse_interact === 'lol')
assert(config.info_node === 'info')
assert(config.info_node === 'https://info')
fs.writeFileSync = tmpWrite
fs.readFileSync = tmpRead
module.exports = fs
Expand Down
18 changes: 18 additions & 0 deletions test/units/transporters/AxonTransport.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,24 @@ describe('AxonTransport', () => {
assert(transport.queue[0].data === 'data')
done()
})
it('should add to queue and remove old queue', (done) => {
let transport = new AxonTransport(opts, daemon)
let _connectCalls = 0
clearInterval(transport._worker)
transport.isConnected = _ => {
_connectCalls++
return false
}
transport.queue = []
for (let i = 0; i < 200; i++) transport.queue.push(['channel', 'data'])
assert(transport.queue.length === 200)
assert(transport.send('channel-custom', 'data-custom') === 200)
assert(_connectCalls === 1)
assert(transport.queue.length === 200)
assert(transport.queue[199].channel === 'channel-custom')
assert(transport.queue[199].data === 'data-custom')
done()
})
})
it('should store status if channel is status', (done) => {
let transport = new AxonTransport(opts, daemon)
Expand Down

0 comments on commit f977096

Please sign in to comment.