Concurrency test with assert.response
This commit is contained in:
parent
1a20ca0bc3
commit
96fc32b24a
@ -4,8 +4,6 @@ var server = require('../../../app/server')();
|
|||||||
var assert = require('../../support/assert');
|
var assert = require('../../support/assert');
|
||||||
var querystring = require('querystring');
|
var querystring = require('querystring');
|
||||||
var libxmljs = require('libxmljs');
|
var libxmljs = require('libxmljs');
|
||||||
var http = require('http');
|
|
||||||
var server_utils = require('../../support/server_utils');
|
|
||||||
|
|
||||||
describe('export.kml', function() {
|
describe('export.kml', function() {
|
||||||
|
|
||||||
@ -225,48 +223,30 @@ it('KML format, unauthenticated, concurrent requests', function(done){
|
|||||||
var concurrency = 4;
|
var concurrency = 4;
|
||||||
var waiting = concurrency;
|
var waiting = concurrency;
|
||||||
|
|
||||||
function onResponse(res) {
|
function validate(err, res) {
|
||||||
//console.log("Response started");
|
//console.log("Response ended");
|
||||||
res.body = '';
|
assert.equal(res.statusCode, 200, res.body);
|
||||||
//res.setEncoding('binary');
|
assert.ok(res.body);
|
||||||
res.on('data', function(chunk){ res.body += chunk; });
|
var snippet = res.body.substr(0, 5);
|
||||||
res.on('end', function(){
|
assert.equal(snippet, "<?xml");
|
||||||
//console.log("Response ended");
|
var cd = res.headers['content-disposition'];
|
||||||
assert.equal(res.statusCode, 200, res.body);
|
assert.equal(true, /^attachment/.test(cd), 'KML is not disposed as attachment: ' + cd);
|
||||||
assert.ok(res.body);
|
assert.equal(true, /filename=multi.kml/gi.test(cd), 'Unexpected KML filename: ' + cd);
|
||||||
var snippet = res.body.substr(0, 5);
|
if ( ! --waiting ) {
|
||||||
assert.equal(snippet, "<?xml");
|
done();
|
||||||
var cd = res.headers['content-disposition'];
|
}
|
||||||
assert.equal(true, /^attachment/.test(cd), 'KML is not disposed as attachment: ' + cd);
|
|
||||||
assert.equal(true, /filename=multi.kml/gi.test(cd), 'Unexpected KML filename: ' + cd);
|
|
||||||
if ( ! --waiting ) {
|
|
||||||
server.close();
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onError(err) {
|
var request = {
|
||||||
console.log("Response error" + err);
|
method: 'GET',
|
||||||
}
|
headers: { host: 'vizzuality.cartodb.com' },
|
||||||
|
url: '/api/v1/sql?' + query
|
||||||
|
};
|
||||||
|
|
||||||
server_utils.startOnNextPort(server, function() {
|
for (var i=0; i<concurrency; ++i) {
|
||||||
var port = server.address().port;
|
|
||||||
//console.log("Listening on port " + port);
|
|
||||||
for (var i=0; i<concurrency; ++i) {
|
|
||||||
//console.log("Sending request");
|
//console.log("Sending request");
|
||||||
http.request({
|
assert.response(server, request, { status: 200 }, validate);
|
||||||
host: 'localhost',
|
}
|
||||||
port: port,
|
|
||||||
path: '/api/v1/sql?' + query,
|
|
||||||
headers: {host: 'vizzuality.cartodb.com'},
|
|
||||||
agent: false // or should this be true ?
|
|
||||||
})
|
|
||||||
.on('response', onResponse)
|
|
||||||
.on('error', onError)
|
|
||||||
.end();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// See https://github.com/Vizzuality/CartoDB-SQL-API/issues/60
|
// See https://github.com/Vizzuality/CartoDB-SQL-API/issues/60
|
||||||
|
Loading…
Reference in New Issue
Block a user