2014-03-07 13:20:41 -05:00
|
|
|
var assert = require('assert')
|
|
|
|
|
|
|
|
module.exports = function() {
|
2014-11-12 06:14:37 -05:00
|
|
|
var server = process.server
|
|
|
|
var express = process.express
|
2014-03-07 13:20:41 -05:00
|
|
|
|
2014-11-12 06:14:37 -05:00
|
|
|
describe('Racy', function() {
|
|
|
|
var on_tarball
|
2014-03-07 14:48:24 -05:00
|
|
|
|
2014-11-12 06:14:37 -05:00
|
|
|
before(function() {
|
|
|
|
express.get('/testexp-racycrash', function(_, res) {
|
|
|
|
res.send({
|
|
|
|
"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 13:20:41 -05:00
|
|
|
|
2014-11-12 06:14:37 -05:00
|
|
|
express.get('/testexp-racycrash/-/test.tar.gz', function(_, res) {
|
|
|
|
on_tarball(res)
|
|
|
|
})
|
|
|
|
})
|
2014-03-07 14:48:24 -05:00
|
|
|
|
2014-11-12 06:14:37 -05:00
|
|
|
it('should not crash on error if client disconnects', function(_cb) {
|
|
|
|
on_tarball = function(res) {
|
|
|
|
res.header('content-length', 1e6)
|
|
|
|
res.write('test test test\n')
|
|
|
|
setTimeout(function() {
|
|
|
|
res.write('test test test\n')
|
|
|
|
res.socket.destroy()
|
|
|
|
cb()
|
|
|
|
}, 200)
|
|
|
|
}
|
2014-03-07 13:20:41 -05:00
|
|
|
|
2015-04-11 12:11:04 -05:00
|
|
|
server.request({ uri: '/testexp-racycrash/-/test.tar.gz' })
|
|
|
|
.then(function (body) {
|
|
|
|
assert.equal(body, 'test test test\n')
|
|
|
|
})
|
2014-03-07 13:20:41 -05:00
|
|
|
|
2014-11-12 06:14:37 -05:00
|
|
|
function cb() {
|
|
|
|
// test for NOT crashing
|
2015-04-11 12:11:04 -05:00
|
|
|
server.request({ uri: '/testexp-racycrash' })
|
|
|
|
.status(200)
|
|
|
|
.then(function () { _cb() })
|
2014-11-12 06:14:37 -05:00
|
|
|
}
|
|
|
|
})
|
2014-03-07 14:48:24 -05:00
|
|
|
|
2015-04-11 12:11:04 -05:00
|
|
|
it('should not store tarball', function () {
|
2014-11-12 06:14:37 -05:00
|
|
|
on_tarball = function(res) {
|
|
|
|
res.socket.destroy()
|
|
|
|
}
|
2014-03-07 14:48:24 -05:00
|
|
|
|
2015-04-11 12:11:04 -05:00
|
|
|
return server.request({ uri: '/testexp-racycrash/-/test.tar.gz' })
|
|
|
|
.body_error('internal server error')
|
2014-11-12 06:14:37 -05:00
|
|
|
})
|
|
|
|
})
|
2014-03-07 13:20:41 -05:00
|
|
|
}
|
|
|
|
|