1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00
verdaccio/test/functional/sanity/racycrash.js

68 lines
2.0 KiB
JavaScript
Raw Normal View History

2018-06-24 10:11:52 +02:00
import {DOMAIN_SERVERS, PORT_SERVER_APP} from '../config.functional';
import {API_ERROR, HEADER_TYPE, HTTP_STATUS} from '../../../src/lib/constants';
2017-12-02 11:19:08 +01:00
export default function(server, express) {
2014-03-07 19:20:41 +01:00
describe('shoul test for unexpected client hangs', () => {
let handleResponseTarball;
2014-03-07 20:48:24 +01:00
2017-12-02 11:19:08 +01:00
beforeAll(function() {
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://${DOMAIN_SERVERS}:${PORT_SERVER_APP}/testexp-racycrash/-/test.tar.gz`,
2017-04-19 21:15:28 +02:00
},
},
},
});
});
2014-03-07 19:20:41 +01:00
express.get('/testexp-racycrash/-/test.tar.gz', function(request, response) {
handleResponseTarball(response);
2017-04-19 21:15:28 +02:00
});
});
2014-03-07 20:48:24 +01:00
2017-12-02 11:19:08 +01:00
test('should not crash on error if client disconnects', callback => {
handleResponseTarball = function(res) {
res.header(HEADER_TYPE.CONTENT_LENGTH, 1e6);
res.write('test test test');
setTimeout(function() {
res.write('-');
// destroy the connection
2017-04-19 21:15:28 +02:00
res.socket.destroy();
cb();
}, HTTP_STATUS.OK);
2017-04-19 21:15:28 +02:00
};
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) {
expect(body).toEqual('test test test');
2017-04-19 21:15:28 +02:00
});
2014-03-07 19:20:41 +01:00
function cb() {
// test for NOT crashing
2017-04-19 21:15:28 +02:00
server.request({uri: '/testexp-racycrash'})
.status(HTTP_STATUS.OK)
2017-04-19 21:15:28 +02:00
.then(function() {
callback();
});
}
2017-04-19 21:15:28 +02:00
});
2014-03-07 20:48:24 +01:00
2017-12-02 11:19:08 +01:00
test('should not store tarball', () => {
handleResponseTarball = 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(API_ERROR.INTERNAL_SERVER_ERROR);
2017-04-19 21:15:28 +02:00
});
});
2017-12-02 11:20:27 +01:00
}