Created
February 10, 2014 12:34
-
-
Save mrvisser/8915100 to your computer and use it in GitHub Desktop.
Reproduces the issue fixed by https://github.com/postwait/node-amqp/pull/293
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('./harness').run(); | |
var _ = require('lodash'); | |
var NUM_SENDBATCH = 100; | |
var NUM_DEVNULL = 100; | |
var enoughIO = false; | |
connection.addListener('ready', function () { | |
puts('connected to ' + connection.serverProperties.product); | |
var exchange = connection.exchange('test-buffer-overwrite', { | |
'type': 'direct', | |
'autoDelete': true | |
}); | |
var qSendBatch = connection.queue('test-buffer-overwrite-sendbatch', {'autoDelete': true}, function() { | |
qSendBatch.bind(exchange, 'test-buffer-overwrite-sendbatch'); | |
var sendBatchRecvCount = 0; | |
qSendBatch.subscribe({'ack': true, 'prefetchCount': 15}, function(data, headers, deliveryInfo, message) { | |
sendBatchRecvCount++; | |
message.acknowledge(); | |
// Perform a secondary check to ensure that this test | |
// is being effectively executed with enough IO | |
if (connection.socket.bufferSize > 0) { | |
enoughIO = true; | |
} | |
// Branch out a batch of new messages to generate a bunch of I/O on the | |
// _sendMethod path | |
_sendDevNullBatch(exchange); | |
}).addCallback(function() { | |
_triggerNewBatch(exchange); | |
}); | |
}); | |
var qDevNull = connection.queue('test-buffer-overwrite-devnull', {'autoDelete': true}, function() { | |
qDevNull.bind(exchange, 'test-buffer-overwrite-devnull'); | |
var devNullRecvCount = 0; | |
qDevNull.subscribe({'ack': true, 'preferchCount': 15}, function(data, headers, deliveryInfo, message) { | |
devNullRecvCount++; | |
message.acknowledge(); | |
// Once we've received each devnull message from each batch, the test has succeeded | |
if (devNullRecvCount === NUM_SENDBATCH * NUM_DEVNULL) { | |
assert.ok(enoughIO, 'Not enough data was generated from this test to detect an issue'); | |
setTimeout(connection.end, 1000); | |
} | |
}); | |
}); | |
}); | |
var _triggerNewBatch = function(exchange) { | |
for (var i = 0; i < NUM_SENDBATCH; i++) { | |
exchange.publish('test-buffer-overwrite-sendbatch', {}); | |
} | |
}; | |
var _sendDevNullBatch = function(exchange) { | |
for (var i = 0; i < NUM_DEVNULL; i++) { | |
exchange.publish('test-buffer-overwrite-devnull', _generateMessage()); | |
} | |
}; | |
var _generateMessage = function() { | |
var result = ''; | |
// The random size generated here needs to be variable enough to | |
// make buffer overwrites matter, and big enough to generate enough | |
// I/O to fill up the socket write buffer | |
var n = _.random(30000, 31000); | |
for (var i = 0; i < n; i++) { | |
result += 'a'; | |
} | |
return {'value': result}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment