Wait until server closes in afterEach

This commit is contained in:
Kevin Sawicki 2017-04-07 16:42:01 -07:00
parent 8a324a9375
commit e2e9e8ae24

View file

@ -26,22 +26,34 @@ const kOneKiloByte = 1024
const kOneMegaByte = kOneKiloByte * kOneKiloByte
describe('net module', function () {
describe('HTTP basics', function () {
let server
beforeEach(function (done) {
server = http.createServer()
server.listen(0, '127.0.0.1', function () {
server.url = 'http://127.0.0.1:' + server.address().port
done()
let server
const connections = new Set()
beforeEach(function (done) {
server = http.createServer()
server.listen(0, '127.0.0.1', function () {
server.url = `http://127.0.0.1:${server.address().port}`
done()
})
server.on('connection', (connection) => {
connections.add(connection)
connection.once('close', () => {
connections.delete(connection)
})
})
})
afterEach(function () {
server.close(function () {
})
afterEach(function (done) {
for (const connection of connections) {
connection.destroy()
}
server.close(function () {
server = null
done()
})
})
describe('HTTP basics', function () {
it('should be able to issue a basic GET request', function (done) {
const requestUrl = '/requestUrl'
server.on('request', function (request, response) {
@ -224,19 +236,7 @@ describe('net module', function () {
})
describe('ClientRequest API', function () {
let server
beforeEach(function (done) {
server = http.createServer()
server.listen(0, '127.0.0.1', function () {
server.url = 'http://127.0.0.1:' + server.address().port
done()
})
})
afterEach(function () {
server.close(function () {
})
server = null
session.defaultSession.webRequest.onBeforeRequest(null)
})
@ -1363,21 +1363,8 @@ describe('net module', function () {
urlRequest.end()
})
})
describe('IncomingMessage API', function () {
let server
beforeEach(function (done) {
server = http.createServer()
server.listen(0, '127.0.0.1', function () {
server.url = 'http://127.0.0.1:' + server.address().port
done()
})
})
afterEach(function () {
server.close()
server = null
})
it('response object should implement the IncomingMessage API', function (done) {
const requestUrl = '/requestUrl'
const customHeaderName = 'Some-Custom-Header-Name'
@ -1544,21 +1531,8 @@ describe('net module', function () {
urlRequest.end()
})
})
describe('Stability and performance', function (done) {
let server
beforeEach(function (done) {
server = http.createServer()
server.listen(0, '127.0.0.1', function () {
server.url = 'http://127.0.0.1:' + server.address().port
done()
})
})
afterEach(function () {
server.close()
server = null
})
it('should free unreferenced, never-started request objects without crash', function (done) {
const requestUrl = '/requestUrl'
ipcRenderer.once('api-net-spec-done', function () {
@ -1574,6 +1548,7 @@ describe('net module', function () {
})
`)
})
it('should not collect on-going requests without crash', function (done) {
const requestUrl = '/requestUrl'
server.on('request', function (request, response) {
@ -1615,6 +1590,7 @@ describe('net module', function () {
urlRequest.end()
`)
})
it('should collect unreferenced, ended requests without crash', function (done) {
const requestUrl = '/requestUrl'
server.on('request', function (request, response) {