Firebase Update

This commit is contained in:
Lukas Nowy
2018-12-22 23:30:39 +01:00
parent befb44764d
commit acffe619b3
11523 changed files with 1614327 additions and 930246 deletions

View File

@ -1,2 +0,0 @@
node_modules
npm-debug.log

View File

@ -5,6 +5,13 @@ matrix:
- node_js: "4"
addons:
postgresql: "9.1"
dist: precise
- node_js: "6"
addons:
postgresql: "9.4"
- node_js: "8"
addons:
postgresql: "9.6"
- node_js: "9"
addons:
postgresql: "9.6"

View File

@ -3,6 +3,14 @@ const EventEmitter = require('events').EventEmitter
const NOOP = function () { }
const remove = (list, value) => {
const i = list.indexOf(value)
if (i !== -1) {
list.splice(i, 1)
}
}
const removeWhere = (list, predicate) => {
const i = list.findIndex(predicate)
@ -157,18 +165,20 @@ class Pool extends EventEmitter {
return result
}
const queueCallback = (err, res, done) => {
clearTimeout(tid)
response.callback(err, res, done)
}
// set connection timeout on checking out an existing client
const tid = setTimeout(() => {
// remove the callback from pending waiters because
// we're going to call it with a timeout error
this._pendingQueue = this._pendingQueue.filter(cb => cb === response.callback)
remove(this._pendingQueue, queueCallback)
response.callback(new Error('timeout exceeded when trying to connect'))
}, this.options.connectionTimeoutMillis)
this._pendingQueue.push(function (err, res, done) {
clearTimeout(tid)
response.callback(err, res, done)
})
this._pendingQueue.push(queueCallback)
return result
}
@ -186,7 +196,7 @@ class Pool extends EventEmitter {
this.emit('error', err, client)
}
this.log('connecting new client')
this.log('checking client timeout')
// connection timeout logic
let tid
@ -205,19 +215,24 @@ class Pool extends EventEmitter {
this.log('connecting new client')
client.connect((err) => {
this.log('new client connected')
if (tid) {
clearTimeout(tid)
}
client.on('error', idleListener)
if (err) {
this.log('client failed to connect', err)
// remove the dead client from our list of clients
this._clients = this._clients.filter(c => c !== client)
if (timeoutHit) {
err.message = 'Connection terminiated due to connection timeout'
err.message = 'Connection terminated due to connection timeout'
}
// this client wont be released, so move on immediately
this._pulseQueue()
cb(err, undefined, NOOP)
} else {
this.log('new client connected')
client.release = release.bind(this, client)
this.emit('connect', client)
this.emit('acquire', client)

View File

@ -1,27 +1,27 @@
{
"_from": "pg-pool@~2.0.3",
"_id": "pg-pool@2.0.3",
"_from": "pg-pool@^2.0.4",
"_id": "pg-pool@2.0.5",
"_inBundle": false,
"_integrity": "sha1-wCIDLIlJ8xKk+R+2QJzgQHa+Mlc=",
"_integrity": "sha512-T4W9qzP2LjItXuXbW6jgAF2AY0jHp6IoTxRhM3GB7yzfBxzDnA3GCm0sAduzmmiCybMqD0+V1HiqIG5X2YWqlQ==",
"_location": "/pg-pool",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "pg-pool@~2.0.3",
"raw": "pg-pool@^2.0.4",
"name": "pg-pool",
"escapedName": "pg-pool",
"rawSpec": "~2.0.3",
"rawSpec": "^2.0.4",
"saveSpec": null,
"fetchSpec": "~2.0.3"
"fetchSpec": "^2.0.4"
},
"_requiredBy": [
"/pg"
],
"_resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-2.0.3.tgz",
"_shasum": "c022032c8949f312a4f91fb6409ce04076be3257",
"_spec": "pg-pool@~2.0.3",
"_where": "D:\\5CHITM\\Diplomarbeit\\smart-shopper\\SmartShopper\\express-server\\node_modules\\pg",
"_resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-2.0.5.tgz",
"_shasum": "f00556fab23f1bbb14b0650ba8d0e447434a1b04",
"_spec": "pg-pool@^2.0.4",
"_where": "D:\\Desktop\\Git\\Firebase\\SmartShopperFirebase\\node_modules\\pg",
"author": {
"name": "Brian M. Carlson"
},
@ -66,5 +66,5 @@
"scripts": {
"test": " node_modules/.bin/mocha && node_modules/.bin/standard"
},
"version": "2.0.3"
"version": "2.0.5"
}

View File

@ -73,6 +73,28 @@ describe('connection timeout', () => {
})
})
it('should not break further pending checkouts on a timeout', (done) => {
const pool = new Pool({ connectionTimeoutMillis: 200, max: 1 })
pool.connect((err, client, releaseOuter) => {
expect(err).to.be(undefined)
pool.connect((err, client) => {
expect(err).to.be.an(Error)
expect(client).to.be(undefined)
releaseOuter()
})
setTimeout(() => {
pool.connect((err, client, releaseInner) => {
expect(err).to.be(undefined)
expect(client).to.not.be(undefined)
releaseInner()
pool.end(done)
})
}, 100)
})
})
it('should timeout on query if all clients are busy', (done) => {
const pool = new Pool({ connectionTimeoutMillis: 100, max: 1 })
pool.connect((err, client, release) => {

View File

@ -1,4 +1,5 @@
'use strict'
const net = require('net')
const co = require('co')
const expect = require('expect.js')
@ -143,4 +144,25 @@ describe('pool error handling', function () {
return pool.end()
}))
})
it('should continue with queued items after a connection failure', (done) => {
const closeServer = net.createServer((socket) => {
socket.destroy()
}).unref()
closeServer.listen(() => {
const pool = new Pool({ max: 1, port: closeServer.address().port })
pool.connect((err) => {
expect(err).to.be.an(Error)
expect(err.message).to.be('Connection terminated unexpectedly')
})
pool.connect((err) => {
expect(err).to.be.an(Error)
expect(err.message).to.be('Connection terminated unexpectedly')
closeServer.close(() => {
pool.end(done)
})
})
})
})
})

View File

@ -33,11 +33,17 @@ describe('pool size of 1', () => {
it('can only send 1 query at a time', co.wrap(function * () {
const pool = new Pool({ max: 1 })
const queries = _.times(20, (i) => {
return pool.query('SELECT COUNT(*) as counts FROM pg_stat_activity')
})
// the query text column name changed in PostgreSQL 9.2
const versionResult = yield pool.query('SHOW server_version_num')
const version = parseInt(versionResult.rows[0].server_version_num, 10)
const queryColumn = version < 90200 ? 'current_query' : 'query'
const queryText = 'SELECT COUNT(*) as counts FROM pg_stat_activity WHERE ' + queryColumn + ' = $1'
const queries = _.times(20, () =>
pool.query(queryText, [queryText]))
const results = yield Promise.all(queries)
const counts = results.map(res => parseInt(res.rows[0].counts), 10)
const counts = results.map(res => parseInt(res.rows[0].counts, 10))
expect(counts).to.eql(_.times(20, i => 1))
return yield pool.end()
}))