Skip to content

Commit 9dbb89a

Browse files
flovilmartArthur Cinader
authored and
Arthur Cinader
committed
Fixes postgres flaky test (#3822)
* Changes expected error code * nits
1 parent ab04641 commit 9dbb89a

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

Diff for: spec/PostgresInitOptions.spec.js

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const Parse = require('parse/node').Parse;
22
const PostgresStorageAdapter = require('../src/Adapters/Storage/Postgres/PostgresStorageAdapter');
33
const postgresURI = 'postgres://localhost:5432/parse_server_postgres_adapter_test_database';
4-
4+
const Config = require('../src/Config');
55
//public schema
66
const databaseOptions1 = {
77
initOptions: {
@@ -28,33 +28,40 @@ const GameScore = Parse.Object.extend({
2828
className: "GameScore"
2929
});
3030

31-
describe('Postgres database init options', () => {
31+
describe_only_db('postgres')('Postgres database init options', () => {
3232
it('should create server with public schema databaseOptions', (done) => {
33+
const config = new Config('test');
34+
// Close the current DB before continueing
35+
config.database.adapter._pgp.end();
3336
reconfigureServer({
3437
databaseAdapter: new PostgresStorageAdapter({
3538
uri: postgresURI, collectionPrefix: 'test_',
3639
databaseOptions: databaseOptions1
3740
})
38-
}).then(done, fail);
41+
}).then(done, done.fail);
3942
});
4043

4144
it("save new GameScore in public schema", function (done) {
4245
var score = new GameScore({ "score": 1337, "playerName": "Sean Plott", "cheatMode": false });
43-
score.save().then(done, fail);
46+
score.save().then(done, done.fail);
4447
});
4548

4649
it('should fail to create server if schema databaseOptions does not exist', (done) => {
50+
const config = new Config('test');
51+
// Close the current DB before continueing
52+
config.database.adapter._pgp.end();
4753
reconfigureServer({
4854
databaseAdapter: new PostgresStorageAdapter({
4955
uri: postgresURI, collectionPrefix: 'test_',
5056
databaseOptions: databaseOptions2
5157
})
5258
}).then(() => {
59+
done.fail('Should not succeed');
60+
}, error => {
61+
// INVALID_SCHEMA error 3F000
62+
// https://www.postgresql.org/docs/9.5/static/errcodes-appendix.html
63+
expect(error.code).toEqual('3F000');
5364
done();
54-
})
55-
.catch(error => {
56-
expect(error.code).toEqual('42P01');
57-
done();
58-
});
65+
});
5966
});
6067
});

Diff for: src/Adapters/Storage/Postgres/PostgresClient.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ export function createClient(uri, databaseOptions) {
2323
}
2424
}
2525

26-
return client;
26+
return { client, pgp };
2727
}

Diff for: src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -403,14 +403,17 @@ export class PostgresStorageAdapter {
403403
// Private
404404
_collectionPrefix: string;
405405
_client;
406+
_pgp;
406407

407408
constructor({
408409
uri,
409410
collectionPrefix = '',
410411
databaseOptions
411412
}) {
412413
this._collectionPrefix = collectionPrefix;
413-
this._client = createClient(uri, databaseOptions);
414+
const { client, pgp } = createClient(uri, databaseOptions);
415+
this._client = client;
416+
this._pgp = pgp;
414417
}
415418

416419
_ensureSchemaCollectionExists(conn) {

0 commit comments

Comments
 (0)