2017-04-19 21:15:28 +02:00
|
|
|
'use strict';
|
|
|
|
|
2017-08-06 21:54:15 +02:00
|
|
|
const assert = require('assert');
|
2014-03-07 19:20:41 +01:00
|
|
|
|
|
|
|
module.exports = function() {
|
2017-08-06 21:54:15 +02:00
|
|
|
const server = process.server;
|
|
|
|
const express = process.express;
|
2014-03-07 19:20:41 +01:00
|
|
|
|
2017-08-06 21:54:15 +02:00
|
|
|
describe('test for unexpected client hangs', function() {
|
2017-04-19 21:15:28 +02:00
|
|
|
let on_tarball;
|
2014-03-07 20:48:24 +01:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
before(function() {
|
2017-08-06 21:54:15 +02:00
|
|
|
express.get('/testexp-racycrash', function(request, response) {
|
|
|
|
response.send({
|
2017-04-19 21:15:28 +02:00
|
|
|
'name': 'testexp-racycrash',
|
|
|
|
'versions': {
|
|
|
|
'0.1.0': {
|
|
|
|
'name': 'testexp_tags',
|
|
|
|
'version': '0.1.0',
|
|
|
|
'dist': {
|
|
|
|
'shasum': 'fake',
|
|
|
|
'tarball': 'http://localhost:55550/testexp-racycrash/-/test.tar.gz',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2014-03-07 19:20:41 +01:00
|
|
|
|
2017-08-06 21:54:15 +02:00
|
|
|
express.get('/testexp-racycrash/-/test.tar.gz', function(request, response) {
|
|
|
|
on_tarball(response);
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
|
|
|
});
|
2014-03-07 20:48:24 +01:00
|
|
|
|
2017-08-06 21:54:15 +02:00
|
|
|
it('should not crash on error if client disconnects', function(callback) {
|
2014-11-12 12:14:37 +01:00
|
|
|
on_tarball = function(res) {
|
2017-04-19 21:15:28 +02:00
|
|
|
res.header('content-length', 1e6);
|
|
|
|
res.write('test test test\n');
|
2014-11-12 12:14:37 +01:00
|
|
|
setTimeout(function() {
|
2017-04-19 21:15:28 +02:00
|
|
|
res.write('test test test\n');
|
|
|
|
res.socket.destroy();
|
|
|
|
cb();
|
|
|
|
}, 200);
|
|
|
|
};
|
2014-03-07 19:20:41 +01:00
|
|
|
|
2017-04-19 21:15:28 +02:00
|
|
|
server.request({uri: '/testexp-racycrash/-/test.tar.gz'})
|
|
|
|
.then(function(body) {
|
|
|
|
assert.equal(body, 'test test test\n');
|
|
|
|
});
|
2014-03-07 19:20:41 +01:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
function cb() {
|
|
|
|
// test for NOT crashing
|
2017-04-19 21:15:28 +02:00
|
|
|
server.request({uri: '/testexp-racycrash'})
|
2015-04-11 19:11:04 +02:00
|
|
|
.status(200)
|
2017-04-19 21:15:28 +02:00
|
|
|
.then(function() {
|
2017-08-06 21:54:15 +02:00
|
|
|
callback();
|
|
|
|
});
|
2014-11-12 12:14:37 +01:00
|
|
|
}
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
2014-03-07 20:48:24 +01:00
|
|
|
|
2017-04-19 21:15:28 +02:00
|
|
|
it('should not store tarball', function() {
|
2014-11-12 12:14:37 +01:00
|
|
|
on_tarball = function(res) {
|
2017-04-19 21:15:28 +02:00
|
|
|
res.socket.destroy();
|
|
|
|
};
|
2014-03-07 20:48:24 +01:00
|
|
|
|
2017-04-19 21:15:28 +02:00
|
|
|
return server.request({uri: '/testexp-racycrash/-/test.tar.gz'})
|
|
|
|
.body_error('internal server error');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2014-03-07 19:20:41 +01:00
|
|
|
|