Patch handleShutdown feature (#4361)
* 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
This commit is contained in:
committed by
Florent Vilmart
parent
de73f3723c
commit
8bf6abfee3
@@ -237,4 +237,23 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
|
|||||||
done();
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -33,4 +33,35 @@ describe('Server Url Checks', () => {
|
|||||||
done();
|
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
spec/PostgresStorageAdapter.spec.js
Normal file
22
spec/PostgresStorageAdapter.spec.js
Normal file
@@ -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();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -574,6 +574,13 @@ export class PostgresStorageAdapter {
|
|||||||
this._pgp = pgp;
|
this._pgp = pgp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleShutdown() {
|
||||||
|
if (!this._client) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this._client.$pool.end();
|
||||||
|
}
|
||||||
|
|
||||||
_ensureSchemaCollectionExists(conn) {
|
_ensureSchemaCollectionExists(conn) {
|
||||||
conn = conn || this._client;
|
conn = conn || this._client;
|
||||||
return conn.none('CREATE TABLE IF NOT EXISTS "_SCHEMA" ( "className" varChar(120), "schema" jsonb, "isParseClass" bool, PRIMARY KEY ("className") )')
|
return conn.none('CREATE TABLE IF NOT EXISTS "_SCHEMA" ( "className" varChar(120), "schema" jsonb, "isParseClass" bool, PRIMARY KEY ("className") )')
|
||||||
|
|||||||
Reference in New Issue
Block a user