Merge pull request #9144 from electron/wait-util-server-closes
Wait until server closes in afterEach in net spec
This commit is contained in:
commit
2933eef07e
1 changed files with 26 additions and 50 deletions
|
@ -26,22 +26,34 @@ const kOneKiloByte = 1024
|
|||
const kOneMegaByte = kOneKiloByte * kOneKiloByte
|
||||
|
||||
describe('net module', function () {
|
||||
describe('HTTP basics', function () {
|
||||
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
|
||||
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 (done) {
|
||||
for (const connection of connections) {
|
||||
connection.destroy()
|
||||
}
|
||||
server.close(function () {
|
||||
server = null
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
server.close(function () {
|
||||
})
|
||||
server = null
|
||||
})
|
||||
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue