Skip to content
Merged
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
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