2018-06-24 03:11:52 -05:00
|
|
|
import {DOMAIN_SERVERS, PORT_SERVER_APP} from '../config.functional';
|
2018-06-23 02:18:31 -05:00
|
|
|
import {API_ERROR, HEADER_TYPE, HTTP_STATUS} from '../../../src/lib/constants';
|
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
export default function(server, express) {
|
2014-03-07 13:20:41 -05:00
|
|
|
|
2018-06-23 02:18:31 -05:00
|
|
|
describe('shoul test for unexpected client hangs', () => {
|
2018-02-03 20:24:38 -05:00
|
|
|
let handleResponseTarball;
|
2014-03-07 14:48:24 -05:00
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
beforeAll(function() {
|
2017-08-06 14:54:15 -05:00
|
|
|
express.get('/testexp-racycrash', function(request, response) {
|
|
|
|
response.send({
|
2017-04-19 14:15:28 -05:00
|
|
|
'name': 'testexp-racycrash',
|
|
|
|
'versions': {
|
|
|
|
'0.1.0': {
|
|
|
|
'name': 'testexp_tags',
|
|
|
|
'version': '0.1.0',
|
|
|
|
'dist': {
|
|
|
|
'shasum': 'fake',
|
2018-06-23 02:18:31 -05:00
|
|
|
'tarball': `http://${DOMAIN_SERVERS}:${PORT_SERVER_APP}/testexp-racycrash/-/test.tar.gz`,
|
2017-04-19 14:15:28 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2014-03-07 13:20:41 -05:00
|
|
|
|
2017-08-06 14:54:15 -05:00
|
|
|
express.get('/testexp-racycrash/-/test.tar.gz', function(request, response) {
|
2018-02-03 20:24:38 -05:00
|
|
|
handleResponseTarball(response);
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
|
|
|
});
|
2014-03-07 14:48:24 -05:00
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
test('should not crash on error if client disconnects', callback => {
|
2018-02-03 20:24:38 -05:00
|
|
|
handleResponseTarball = function(res) {
|
2018-06-23 02:18:31 -05:00
|
|
|
res.header(HEADER_TYPE.CONTENT_LENGTH, 1e6);
|
2018-02-03 20:24:38 -05:00
|
|
|
res.write('test test test');
|
2014-11-12 06:14:37 -05:00
|
|
|
setTimeout(function() {
|
2018-02-03 20:24:38 -05:00
|
|
|
res.write('-');
|
|
|
|
// destroy the connection
|
2017-04-19 14:15:28 -05:00
|
|
|
res.socket.destroy();
|
|
|
|
cb();
|
2018-06-23 02:18:31 -05:00
|
|
|
}, HTTP_STATUS.OK);
|
2017-04-19 14:15:28 -05:00
|
|
|
};
|
2014-03-07 13:20:41 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
server.request({uri: '/testexp-racycrash/-/test.tar.gz'})
|
|
|
|
.then(function(body) {
|
2018-02-03 20:24:38 -05:00
|
|
|
expect(body).toEqual('test test test');
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
2014-03-07 13:20:41 -05:00
|
|
|
|
2014-11-12 06:14:37 -05:00
|
|
|
function cb() {
|
|
|
|
// test for NOT crashing
|
2017-04-19 14:15:28 -05:00
|
|
|
server.request({uri: '/testexp-racycrash'})
|
2018-06-23 02:18:31 -05:00
|
|
|
.status(HTTP_STATUS.OK)
|
2017-04-19 14:15:28 -05:00
|
|
|
.then(function() {
|
2017-08-06 14:54:15 -05:00
|
|
|
callback();
|
|
|
|
});
|
2014-11-12 06:14:37 -05:00
|
|
|
}
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
2014-03-07 14:48:24 -05:00
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
test('should not store tarball', () => {
|
2018-02-03 20:24:38 -05:00
|
|
|
handleResponseTarball = function(res) {
|
2017-04-19 14:15:28 -05:00
|
|
|
res.socket.destroy();
|
|
|
|
};
|
2014-03-07 14:48:24 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
return server.request({uri: '/testexp-racycrash/-/test.tar.gz'})
|
2018-06-23 02:18:31 -05:00
|
|
|
.body_error(API_ERROR.INTERNAL_SERVER_ERROR);
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
|
|
|
});
|
2017-12-02 05:20:27 -05:00
|
|
|
}
|