Skip to content

Commit 2b9b336

Browse files
authored
Fix flaky postgres test (#7228)
* Fix flaky postgres test * add pgcrypto extension to test * fix postgres ref link CONTRIBUTING guide and add pgcrypto extension * Update CONTRIBUTING.md
1 parent c4aadc9 commit 2b9b336

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Once you have babel running in watch mode, you can start making changes to parse
112112

113113
If your pull request introduces a change that may affect the storage or retrieval of objects, you may want to make sure it plays nice with Postgres.
114114

115-
* Run the tests against the postgres database with `PARSE_SERVER_TEST_DB=postgres PARSE_SERVER_TEST_DATABASE_URI=postgres://postgres:password@localhost:5432/parse_server_postgres_adapter_test_database npm run testonly`. You'll need to have postgres running on your machine and setup [appropriately](https://github.com/parse-community/parse-server/blob/master/.travis.yml#L43) or use [`Docker`](#run-a-parse-postgres-with-docker).
115+
* Run the tests against the postgres database with `PARSE_SERVER_TEST_DB=postgres PARSE_SERVER_TEST_DATABASE_URI=postgres://postgres:password@localhost:5432/parse_server_postgres_adapter_test_database npm run testonly`. You'll need to have postgres running on your machine and setup [appropriately](https://github.com/parse-community/parse-server/blob/master/scripts/before_script_postgres.sh) or use [`Docker`](#run-a-parse-postgres-with-docker).
116116
* The Postgres adapter has a special debugger that traces all the sql commands. You can enable it with setting the environment variable `PARSE_SERVER_LOG_LEVEL=debug`
117117
* If your feature is intended to only work with MongoDB, you should disable PostgreSQL-specific tests with:
118118

@@ -135,7 +135,7 @@ If your pull request introduces a change that may affect the storage or retrieva
135135
[PostGIS images (select one with v2.2 or higher) on docker dashboard](https://hub.docker.com/r/postgis/postgis) is based off of the official [postgres](https://registry.hub.docker.com/_/postgres/) image and will work out-of-the-box (as long as you create a user with the necessary extensions for each of your Parse databases; see below). To launch the compatible Postgres instance, copy and paste the following line into your shell:
136136

137137
```
138-
docker run -d --name parse-postgres -p 5432:5432 -e POSTGRES_PASSWORD=password --rm postgis/postgis:11-3.0-alpine && sleep 20 && docker exec -it parse-postgres psql -U postgres -c 'CREATE DATABASE parse_server_postgres_adapter_test_database;' && docker exec -it parse-postgres psql -U postgres -c 'CREATE EXTENSION postgis;' -d parse_server_postgres_adapter_test_database && docker exec -it parse-postgres psql -U postgres -c 'CREATE EXTENSION postgis_topology;' -d parse_server_postgres_adapter_test_database
138+
docker run -d --name parse-postgres -p 5432:5432 -e POSTGRES_PASSWORD=password --rm postgis/postgis:11-3.0-alpine && sleep 20 && docker exec -it parse-postgres psql -U postgres -c 'CREATE DATABASE parse_server_postgres_adapter_test_database;' && docker exec -it parse-postgres psql -U postgres -c 'CREATE EXTENSION pgcrypto; CREATE EXTENSION postgis;' -d parse_server_postgres_adapter_test_database && docker exec -it parse-postgres psql -U postgres -c 'CREATE EXTENSION postgis_topology;' -d parse_server_postgres_adapter_test_database
139139
```
140140
To stop the Postgres instance:
141141

scripts/before_script_postgres.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ echo "[SCRIPT] Before Script :: Setup Parse DB for Postgres"
77
PGPASSWORD=postgres psql -v ON_ERROR_STOP=1 -h localhost -U postgres <<-EOSQL
88
CREATE DATABASE parse_server_postgres_adapter_test_database;
99
\c parse_server_postgres_adapter_test_database;
10+
CREATE EXTENSION pgcrypto;
1011
CREATE EXTENSION postgis;
1112
CREATE EXTENSION postgis_topology;
1213
EOSQL

spec/PostgresStorageAdapter.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ describe_only_db('postgres')('PostgresStorageAdapter', () => {
165165
]);
166166
//Postgres won't take advantage of the index until it has a lot of records because sequential is faster for small db's
167167
await client.none(
168-
'INSERT INTO $1:name ($2:name, $3:name) SELECT MD5(random()::text), MD5(random()::text) FROM generate_series(1,5000)',
168+
'INSERT INTO $1:name ($2:name, $3:name) SELECT gen_random_uuid(), gen_random_uuid() FROM generate_series(1,5000)',
169169
[tableName, 'objectId', 'username']
170170
);
171171
const caseInsensitiveData = 'bugs';
@@ -245,7 +245,7 @@ describe_only_db('postgres')('PostgresStorageAdapter', () => {
245245
//Postgres won't take advantage of the index until it has a lot of records because sequential is faster for small db's
246246
const client = adapter._client;
247247
await client.none(
248-
'INSERT INTO $1:name ($2:name, $3:name) SELECT MD5(random()::text), MD5(random()::text) FROM generate_series(1,5000)',
248+
'INSERT INTO $1:name ($2:name, $3:name) SELECT gen_random_uuid(), gen_random_uuid() FROM generate_series(1,5000)',
249249
[tableName, 'objectId', 'username']
250250
);
251251
const caseInsensitiveData = 'bugs';
@@ -303,7 +303,7 @@ describe_only_db('postgres')('PostgresStorageAdapter', () => {
303303
//Postgres won't take advantage of the index until it has a lot of records because sequential is faster for small db's
304304
const client = adapter._client;
305305
await client.none(
306-
'INSERT INTO $1:name ($2:name, $3:name) SELECT MD5(random()::text), MD5(random()::text) FROM generate_series(1,5000)',
306+
'INSERT INTO $1:name ($2:name, $3:name) SELECT gen_random_uuid(), gen_random_uuid() FROM generate_series(1,5000)',
307307
[tableName, 'objectId', 'username']
308308
);
309309

@@ -345,11 +345,11 @@ describe_only_db('postgres')('PostgresStorageAdapter', () => {
345345
//Postgres won't take advantage of the index until it has a lot of records because sequential is faster for small db's
346346
const client = adapter._client;
347347
await client.none(
348-
'INSERT INTO $1:name ($2:name, $3:name) SELECT MD5(random()::text), MD5(random()::text) FROM generate_series(1,5000)',
348+
'INSERT INTO $1:name ($2:name, $3:name) SELECT gen_random_uuid(), gen_random_uuid() FROM generate_series(1,5000)',
349349
[firstTableName, 'objectId', uniqueField]
350350
);
351351
await client.none(
352-
'INSERT INTO $1:name ($2:name, $3:name) SELECT MD5(random()::text), MD5(random()::text) FROM generate_series(1,5000)',
352+
'INSERT INTO $1:name ($2:name, $3:name) SELECT gen_random_uuid(), gen_random_uuid() FROM generate_series(1,5000)',
353353
[secondTableName, 'objectId', uniqueField]
354354
);
355355

0 commit comments

Comments
 (0)