diff --git a/resources/buildConfigDefinitions.js b/resources/buildConfigDefinitions.js index ffe5b2e65d..99ddb24743 100644 --- a/resources/buildConfigDefinitions.js +++ b/resources/buildConfigDefinitions.js @@ -1,11 +1,11 @@ /** * Parse Server Configuration Builder - * + * * This module builds the definitions file (src/Options/Definitions.js) * from the src/Options/index.js options interfaces. * The Definitions.js module is responsible for the default values as well * as the mappings for the CLI. - * + * * To rebuild the definitions file, run * `$ node resources/buildConfigDefinitions.js` */ diff --git a/spec/ParseLiveQueryServer.spec.js b/spec/ParseLiveQueryServer.spec.js index 86a68b5694..deebaa3b39 100644 --- a/spec/ParseLiveQueryServer.spec.js +++ b/spec/ParseLiveQueryServer.spec.js @@ -474,7 +474,7 @@ describe('ParseLiveQueryServer', function() { // Trigger disconnect event parseWebSocket.emit('disconnect'); expect(spy).toHaveBeenCalled(); - // call for ws_connect, another for ws_disconnect + // call for ws_connect, another for ws_disconnect expect(spy.calls.count()).toBe(2); }); diff --git a/spec/helper.js b/spec/helper.js index 109f1b0716..367afc2224 100644 --- a/spec/helper.js +++ b/spec/helper.js @@ -116,32 +116,45 @@ if (process.env.PARSE_SERVER_TEST_CACHE === 'redis') { const openConnections = {}; // Set up a default API server for testing with default configuration. -var server; +var parseServer; // Allows testing specific configurations of Parse Server const reconfigureServer = changedConfiguration => { return new Promise((resolve, reject) => { - if (server) { - return server.close(() => { - server = undefined; + if (parseServer) { + return parseServer.server.close(() => { + parseServer.handleShutdown(); + parseServer = undefined; reconfigureServer(changedConfiguration).then(resolve, reject); }); } try { + databaseAdapter.handleShutdown(); const newConfiguration = Object.assign({}, defaultConfiguration, changedConfiguration, { __indexBuildCompletionCallbackForTests: indexBuildPromise => indexBuildPromise.then(resolve, reject), mountPath: '/1', port, }); + if (process.env.PARSE_SERVER_TEST_DB === 'postgres') { + databaseAdapter = new PostgresStorageAdapter({ + uri: process.env.PARSE_SERVER_TEST_DATABASE_URI || postgresURI, + collectionPrefix: 'test_', + }); + } else { + databaseAdapter = new MongoStorageAdapter({ + uri: mongoURI, + collectionPrefix: 'test_', + }); + } + newConfiguration.databaseAdapter = databaseAdapter cache.clear(); - const parseServer = ParseServer.start(newConfiguration); + parseServer = ParseServer.start(newConfiguration); parseServer.app.use(require('./testing-routes').router); parseServer.expressApp.use('/1', (err) => { console.error(err); fail('should not call next'); }); - server = parseServer.server; - server.on('connection', connection => { + parseServer.server.on('connection', connection => { const key = `${connection.remoteAddress}:${connection.remotePort}`; openConnections[key] = connection; connection.on('close', () => { delete openConnections[key] }); diff --git a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js index 4560ab9b2e..188107fa01 100644 --- a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js +++ b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js @@ -574,6 +574,15 @@ export class PostgresStorageAdapter { this._pgp = pgp; } + handleShutdown() { + if (!this._pgp) { + return; + } + // For immediate app exit, shutting down all connection pools + // See API: http://vitaly-t.github.io/pg-promise/module-pg-promise.html#~end + this._pgp.end(); + } + _ensureSchemaCollectionExists(conn) { conn = conn || this._client; return conn.none('CREATE TABLE IF NOT EXISTS "_SCHEMA" ( "className" varChar(120), "schema" jsonb, "isParseClass" bool, PRIMARY KEY ("className") )') diff --git a/src/Options/index.js b/src/Options/index.js index d21e715270..5d5f4ecc8b 100644 --- a/src/Options/index.js +++ b/src/Options/index.js @@ -116,7 +116,7 @@ export interface ParseServerOptions { enableSingleSchemaCache: ?boolean; // = false /* Sets the number of characters in generated object id's, default 10 */ objectIdSize: ?number; // = 10 - /* The port to run the ParseServer. defaults to 1337. + /* The port to run the ParseServer. defaults to 1337. :ENV: PORT */ port: ?number; // = 1337 /* The host to serve ParseServer on. defaults to 0.0.0.0 */