Skip to content

Instantly share code, notes, and snippets.

@sentientwaffle
Last active August 29, 2015 14:03
Show Gist options
  • Save sentientwaffle/a428e03036be50bc57ba to your computer and use it in GitHub Desktop.
Save sentientwaffle/a428e03036be50bc57ba to your computer and use it in GitHub Desktop.
test("rogue socket.close, then flush", function(t) {
var mc, done
dgramServer(function(pool, _done) {
mc = new MetricsAgent(pool)
var socket = mc.socket
, _close = mc.socket.close
mc.socket.close = function() {
console.trace()
_close.apply(socket, arguments)
};
pool.emit("health")
mc.histogram("foo", 123)
done = _done
}, function(msg) {
mc.counter("THIS_WILL_SEND_AFTER_THE_SOCKET_IS_CLOSED")
// Someone closes the socket out from under us
mc.socket.close()
// Wait until PacketQueue's interval timer wakes up.
setTimeout(function() { done(); t.end() }, 1500)
})
})
Trace
at Socket.mc.socket.close (/home/x/Code/modules/zag/agent/test/agent.test.js:65:19)
at Socket.<anonymous> (/home/x/Code/modules/zag/agent/test/agent.test.js:74:17)
at Socket.EventEmitter.emit (events.js:98:17)
at UDP.onMessage (dgram.js:440:8)
{ domain: null,
_events: { error: [Function] },
_maxListeners: 10,
_handle: null,
_receiving: false,
_bindState: 2,
type: 'udp4',
fd: null,
close: [Function],
_sendQueue: undefined }
dgram.js:420
throw new Error('Not running'); // error message from dgram_legacy.js
^
Error: Not running
at Socket._healthCheck (dgram.js:420:11)
at Socket.send (dgram.js:272:8)
at MetricsAgent.sendBulk (/home/x/Code/modules/zag/agent/lib/agent.js:104:15)
at PacketQueue.send (/home/x/Code/modules/zag/agent/lib/agent.js:30:11)
at PacketQueue.sendPacket (/home/x/Code/modules/zag/agent/lib/packet-queue.js:46:8)
at PacketQueue.flush (/home/x/Code/modules/zag/agent/lib/packet-queue.js:51:31)
at null.<anonymous> (/home/x/Code/modules/zag/agent/lib/packet-queue.js:23:50)
at wrapper [as _onTimeout] (timers.js:252:14)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment