Skip to content

Commit

Permalink
Patch handleShutdown feature (#4361)
Browse files Browse the repository at this point in the history
* Add handleShutdown Test of MongoStorageAdapter.

* Add `handleShutdown` function in PostgresStorageAdapter, with it's test.

* Replace the _pgp to _client

* Use  `adapter._client.$pool.ending` to ckeck is ending

* Add `handleShutdown()` in ParseServer.spec.js

* Trigger

* Set Server to Default
  • Loading branch information
trylovetom authored and flovilmart committed Nov 18, 2017
1 parent de73f37 commit 8bf6abf
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
19 changes: 19 additions & 0 deletions spec/MongoStorageAdapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,23 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
done();
});
});

it('handleShutdown, close connection', (done) => {
const adapter = new MongoStorageAdapter({ uri: databaseURI });

const schema = {
fields: {
array: { type: 'Array' },
object: { type: 'Object' },
date: { type: 'Date' },
}
};

adapter.createObject('MyClass', schema, {}).then(() => {
expect(adapter.database.serverConfig.isConnected()).toEqual(true);
adapter.handleShutdown()
expect(adapter.database.serverConfig.isConnected()).toEqual(false);
done();
});
});
});
31 changes: 31 additions & 0 deletions spec/ParseServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,35 @@ describe('Server Url Checks', () => {
done();
});
});

it('handleShutdown, close connection', (done) => {
var MongoStorageAdapter = require('../src/Adapters/Storage/Mongo/MongoStorageAdapter');
const PostgresStorageAdapter = require('../src/Adapters/Storage/Postgres/PostgresStorageAdapter');
const mongoURI = 'mongodb://localhost:27017/parseServerMongoAdapterTestDatabase';
const postgresURI = 'postgres://localhost:5432/parse_server_postgres_adapter_test_database';
let databaseAdapter;
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_',
});
}
const newConfiguration = Object.assign({}, defaultConfiguration, { databaseAdapter });
const parseServer = ParseServer.start(newConfiguration, () => {
parseServer.handleShutdown();
parseServer.server.close((err) => {
if (err) {
done.fail('Close Server Error')
}
reconfigureServer({}).then(() => {
done();
});
});
});
});
});
22 changes: 22 additions & 0 deletions spec/PostgresStorageAdapter.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const PostgresStorageAdapter = require('../src/Adapters/Storage/Postgres/PostgresStorageAdapter');
const databaseURI = 'postgres://localhost:5432/parse_server_postgres_adapter_test_database';

describe_only_db('postgres')('PostgresStorageAdapter', () => {
beforeEach(done => {
const adapter = new PostgresStorageAdapter({ uri: databaseURI })
.deleteAllClasses()
.then(() => {
adapter.handleShutdown();
}, fail)
.catch(done);
});

it('handleShutdown, close connection', (done) => {
const adapter = new PostgresStorageAdapter({ uri: databaseURI });

expect(adapter._client.$pool.ending).toEqual(false);
adapter.handleShutdown();
expect(adapter._client.$pool.ending).toEqual(true);
done();
});
});
7 changes: 7 additions & 0 deletions src/Adapters/Storage/Postgres/PostgresStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,13 @@ export class PostgresStorageAdapter {
this._pgp = pgp;
}

handleShutdown() {
if (!this._client) {
return
}
this._client.$pool.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

0 comments on commit 8bf6abf

Please sign in to comment.