Skip to content

Instantly share code, notes, and snippets.

@jkrems
Last active August 29, 2015 14:23
Show Gist options
  • Save jkrems/605a63f4ac068f42de30 to your computer and use it in GitHub Desktop.
Save jkrems/605a63f4ac068f42de30 to your computer and use it in GitHub Desktop.
Edge case for node-inspector NetworkAgent
diff --git a/test/NetworkAgent.js b/test/NetworkAgent.js
index f63309b..0d21572 100644
--- a/test/NetworkAgent.js
+++ b/test/NetworkAgent.js
@@ -177,6 +177,15 @@ describe('NetworkAgent', function() {
commandlet.stdin.write('send GET request\n');
});
+
+ xit('should report queued requests', function(done) {
+ frontendClient.once('Network.requestWillBeSent', function(data) {
+ expect(data.documentURL).to.be.equal('http://127.0.0.1:1023/');
+ done();
+ });
+
+ commandlet.stdin.write('send queued GET request\n');
+ });
});
diff --git a/test/fixtures/Commandlet.js b/test/fixtures/Commandlet.js
index 88d4be5..692b569 100644
--- a/test/fixtures/Commandlet.js
+++ b/test/fixtures/Commandlet.js
@@ -17,6 +17,23 @@ var commands = {
'pause': function() {
debugger;
},
+ 'send queued GET request': function() {
+ http.get({
+ method: 'GET',
+ host: '127.0.0.1',
+ port: 1023, // would trigger a ECONNREFUSED immediately
+ agent: new http.Agent({
+ // -1 simulates an exhausted connection pool
+ maxSockets: -1
+ })
+ }).end();
+ },
+ 'send invalid hostname GET request': function() {
+ http.get({
+ method: 'GET',
+ host: 'invalid.hostname.tld'
+ }).end();
+ },
'send GET request': function() {
startServer({
res: {
// Run with io.js 2.x
'use strict';
var http = require('http');
var addRequest = http.Agent.prototype.addRequest;
http.Agent.prototype.addRequest = function patched_addRequest(req, options) {
req.once('socket', function() {
console.log('Got socket for %j', options.pathname);
});
return addRequest.apply(this, arguments);
};
var server = http.createServer(function(req, res) {
setTimeout(function() {
res.end('ok');
}, 750);
});
server.listen(0, function() {
var port = server.address().port;
function makeRequest(pathname) {
return new Promise(function(resolve, reject) {
var req = http.get({
host: '127.0.0.1', pathname: pathname, port: port, headers: { Host: 'api.reddit.com' }
}, function(res) {
res.resume();
resolve(res.statusCode);
}).on('error', reject);
// abort if the request takes >1s
setTimeout(function() {
resolve(`ETIMEDOUT: ${pathname}`);
req.abort();
}, 1000);
});
}
http.globalAgent.maxSockets = 5;
var paths = 'abcdefghijklmno'.split('').map(function(letter) {
return `/${letter}`;
});
Promise.all(paths.map(makeRequest)).then(function(codes) {
console.log(codes);
server.close();
}, throwError);
});
function throwError(err) {
setImmediate(function() { throw err; });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment