Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch The Lost Function (handleShutdown) of PostgresStorageAdapter #4359

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions resources/buildConfigDefinitions.js
Original file line number Diff line number Diff line change
@@ -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`
*/
Expand Down
2 changes: 1 addition & 1 deletion spec/ParseLiveQueryServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
27 changes: 20 additions & 7 deletions spec/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] });
Expand Down
9 changes: 9 additions & 0 deletions src/Adapters/Storage/Postgres/PostgresStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") )')
Expand Down
2 changes: 1 addition & 1 deletion src/Options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down