Skip to content

Commit 7121ea0

Browse files
authored
Fixed issue that prevented Postgres Tests from passing locally and on any port other than 5432 in travis (#6531)
* Attempting to fix Postgres issue * Attempting to fix Postgres issue trying to stop loop * Attempting to fix Postgres isolating postgres calls * Attempting to fix Postgres issue Separating jobs * Attempting to fix postgres * Attempting to fix postgres * Attempting to fix postgres Separating builds again * Attempting to fix postgres * Attempting to fix postgres * Attempting to fix postgres Just added back version 10, just in case it gets called * Attempting to fix postgres * Attempting to fix postgres * Attempting to fix postgres * Attempting to fix postgres * Attempting to fix postgres * Attempting to fix postgres * Attempting to fix postgres * Attempting to fix postgres * Attempting to fix postgres * Attempting to fix postgres * Update .travis.yml * Attempting to fix postgres Removed postgres installs from unneeded test cases. Added the ability to test Postgres 10 and 11 * Attempting to fix postgres * Attempting to fix postgres * Attempting to fix postgres * Attempting to fix postgres Added test for postgres 12 that's allowed to fail * Attempting to fix postgres * Attempting to fix postgres Second round to see if it fails eventually * Attempting to fix postgres Round 3 * Attempting to fix postgres Allowing all postgres to fail since it seems to occur randomly * Temporary fix: separated mongo and postgres in travis Now the mongo and postgres scripts are independent of each other to prevent the `ERROR: could not access file "$libdir/postgis-2.4": No such file or directory` of showing up in the rest of the builds. In addition, a test for postgres-12 has been added for future compatibility. Both the postgres-11 and postgres-12 have been added to `allow_failures` because the aforementioned error still creeps up. Important note is that the error has nothing to do with compatibility with postgres, but rather seems to be an error of how postgres (or really postgis) is being referenced in the respective travis distribution. Lastly, this error, if truly random should appear less than before as the postgres scripts aren't being run for every build as it previously was running. * Allowing all postgres to fail * Allowing multiple names to fail * Removing preinstalled versions of postgres from list Seeing if this gets rid of the random error * Use postgres made for dist * Second round * Round 3 * Round 4 * Round 5 * Fixed issue with random postgres fail Removing the native postgres builds at the right time seems to have fixed the random error from before. The postgres tests are now not allowed to fail. * Added back postgres 11 and 12 to allow_failures The actual problem is fixed, but it seems there are some instability with some of the test cases for postgres that need to be addressed at another time. The issues that pop up are: - Postgres-11 ```Failures: 1) Cloud Code cloud jobs should set the message / success on the job Message: Expected undefined to equal 'hello'. Stack: Error: Expected undefined to equal 'hello'. at <Jasmine> at req.message.then.then.jobStatus (/home/travis/build/parse-community/parse-server/spec/CloudCode.spec.js:1571:46) at process._tickCallback (internal/process/next_tick.js:68:7) ``` - Postgres-12 ``` Failures: 1) Cloud Code cloud jobs should set the message / success on the job Message: Expected undefined to equal 'hello'. Stack: Error: Expected undefined to equal 'hello'. at <Jasmine> at req.message.then.then.jobStatus (/home/travis/build/parse-community/parse-server/spec/CloudCode.spec.js:1571:46) at process._tickCallback (internal/process/next_tick.js:68:7) Message: Expected 'running' to equal 'succeeded'. Stack: Error: Expected 'running' to equal 'succeeded'. at <Jasmine> at promise.then.then.jobStatus (/home/travis/build/parse-community/parse-server/spec/CloudCode.spec.js:1580:45) at process._tickCallback (internal/process/next_tick.js:68:7) ``` * added travis scripts for postgres * Setting up before_install and before_script This should shrink the footprint of the file and and reduce the redundancy of calls for postgres. Added support for testing of Postgres 9 and 10 in the scripts, not adding the tests though * make scripts executable * Update .travis.yml * add sourcing in script * trying to fix source * fixing env var in script * fixed ; near then * Cleaning up travis file removed old lines * Finishing clean up * Fixing allow_failures since "name" was removed * Update .travis.yml * Removed Postgres 11 from allow_failures * I think using travis default postgres port of 5433 will allow us to not have to remove anything from the image * Switching travis to postgres port 5433 * modifying script for test * modifying script for test * modifying script for test * reverting back to working way with removing postgres from image * Reverted back to removing postgres from image * removing postgres 12 * removed postgres-12 from allow_failures * updated postgres method from deprecated. Also updating postgis to 3.0 * updated postgis to 3.0 * Update .travis.yml * fix Postgres test issues that causes some tests to fail locally when using PARSE_SERVER_TEST_DATABASE_URI * removed dependence on creating adapter locally in testcase and use config instead. * fixed one more potential issue with postgres adapter * modified travis and script to leverage PARSE_SERVER_TEST_DATABASE_URI * changes to before install to reduce time * add updated port to script for psql connection * fixed arg for psql * added back conf file as it probably contains the default permissions * seeing if stopping/starting postgres back-to-back was the issue * checking fix * revert to working version of install script * leave default port * removing uninstall of postgres from script * looks like postgres won't start until the others are removed * forgoing using posgres service and starting directly, hoping it allows to skip remove * removed sudo for starting postgres * adding back sude, but using default user for postgres * fix * don't start service * init db cluster before starting * remove folder befor init * remove folder befor init * still have to stop service * switch ports after new configs are made * switch ports after new configs are made * went back to removing to get it to start properly * seeing if you can use postgres installaition out of the box * seeing if you can use postgres installaition out of the box * copy hba file, then stop,start * testing using port as argument * working version * round 2 * updated documentation to reflect changes * use restart instead of stop/start for postgres * removed extra lines to ensure consistency with future builds * reload instead of restart postgres * restart postgres since we can't currently connect * Switch to testonly for postgres * run testonly * Declare as mongo test since it's handed coded to a mongo uri
1 parent a9dba44 commit 7121ea0

8 files changed

+23
-36
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
packages:
4848
- postgresql-11-postgis-3
4949
- postgresql-11-postgis-3-scripts
50-
env: POSTGRES_MAJOR_VERSION=11 PARSE_SERVER_TEST_DB=postgres
50+
env: POSTGRES_MAJOR_VERSION=11 PARSE_SERVER_TEST_DB=postgres PARSE_SERVER_TEST_DATABASE_URI=postgres://localhost:5433/parse_server_postgres_adapter_test_database
5151
before_install: bash scripts/before_install_postgres.sh
5252
before_script: bash scripts/before_script_postgres.sh
5353
- stage: release

CONTRIBUTING.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,18 @@ Once you have babel running in watch mode, you can start making changes to parse
5858

5959
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.
6060

61-
* Run the tests against the postgres database with `PARSE_SERVER_TEST_DB=postgres npm test`. You'll need to have postgres running on your machine and setup [appropriately](https://github.com/parse-community/parse-server/blob/master/.travis.yml#L37) or use [`Docker`](#run-a-parse-postgres-with-docker).
61+
* 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).
6262
* 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`
6363
* If your feature is intended to only work with MongoDB, you should disable PostgreSQL-specific tests with:
6464

6565
- `describe_only_db('mongo')` // will create a `describe` that runs only on mongoDB
6666
- `it_only_db('mongo')` // will make a test that only runs on mongo
6767
- `it_exclude_dbs(['postgres'])` // will make a test that runs against all DB's but postgres
68+
* Similarly, if your feature is intended to only work with PostgreSQL, you should disable MongoDB-specific tests with:
69+
70+
- `describe_only_db('postgres')` // will create a `describe` that runs only on postgres
71+
- `it_only_db('postgres')` // will make a test that only runs on postgres
72+
- `it_exclude_dbs(['mongo'])` // will make a test that runs against all DB's but mongo
6873

6974
#### Run a Parse Postgres with Docker
7075

scripts/before_install_postgres.sh

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,28 @@
22

33
set -e
44

5-
source ~/.nvm/nvm.sh
6-
75
echo "[SCRIPT] Before Install Script :: Setup Postgres ${POSTGRES_MAJOR_VERSION}"
86

9-
nvm install $NODE_VERSION
10-
nvm use $NODE_VERSION
11-
npm install -g greenkeeper-lockfile@1
12-
13-
sudo sed -i 's/port = 5433/port = 5432/' /etc/postgresql/${POSTGRES_MAJOR_VERSION}/main/postgresql.conf
14-
157
if [[ $POSTGRES_MAJOR_VERSION -lt 11 ]]; then
168
# Setup postgres 9 or 10
9+
sudo sed -i 's/port = 5432/port = 5433/' /etc/postgresql/${POSTGRES_MAJOR_VERSION}/main/postgresql.conf
10+
11+
# Stop the current running service
1712
sudo service postgresql stop
18-
13+
1914
# Remove correct version of postgres
2015
if [[ $POSTGRES_MAJOR_VERSION -lt 10 ]]; then
2116
sudo apt-get remove -q 'postgresql-10.*'
2217
else
2318
sudo apt-get remove -q 'postgresql-9.*'
2419
fi
2520

26-
sudo service postgresql start ${POSTGRES_MAJOR_VERSION}
21+
sudo service postgresql start
2722

2823
else
29-
3024
# Setup postgres 11 or higher
25+
26+
#Copy defauilt hba config file and tell postgres to restart
3127
sudo cp /etc/postgresql/{10,${POSTGRES_MAJOR_VERSION}}/main/pg_hba.conf
32-
sudo service postgresql stop
33-
# Remove previous versions of postgres
34-
sudo apt-get remove -q 'postgresql-9.*' 'postgresql-10.*'
35-
sudo service postgresql start ${POSTGRES_MAJOR_VERSION}
28+
sudo systemctl restart postgresql@${POSTGRES_MAJOR_VERSION}-main
3629
fi

scripts/before_script_postgres.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ set -e
44

55
echo "[SCRIPT] Before Script :: Setup Parse DB for Postgres ${POSTGRES_MAJOR_VERSION}"
66

7-
node -e 'require("./lib/index.js")'
8-
9-
psql -v ON_ERROR_STOP=1 --username "postgres" --dbname "${POSTGRES_DB}" <<-EOSQL
7+
psql -v ON_ERROR_STOP=1 -p 5433 --username "postgres" --dbname "${POSTGRES_DB}" <<-EOSQL
108
CREATE DATABASE parse_server_postgres_adapter_test_database;
119
\c parse_server_postgres_adapter_test_database;
1210
CREATE EXTENSION postgis;

spec/GridFSBucketStorageAdapter.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ async function expectMissingFile(gfsAdapter, name) {
1414
}
1515
}
1616

17-
describe('GridFSBucket and GridStore interop', () => {
17+
describe_only_db('mongo')('GridFSBucket and GridStore interop', () => {
1818
beforeEach(async () => {
1919
const gsAdapter = new GridStoreAdapter(databaseURI);
2020
const db = await gsAdapter._connect();

spec/ParseQuery.FullTextSearch.spec.js

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
11
'use strict';
22

3-
const MongoStorageAdapter = require('../lib/Adapters/Storage/Mongo/MongoStorageAdapter')
4-
.default;
5-
const mongoURI =
6-
'mongodb://localhost:27017/parseServerMongoAdapterTestDatabase';
7-
const PostgresStorageAdapter = require('../lib/Adapters/Storage/Postgres/PostgresStorageAdapter')
8-
.default;
9-
const postgresURI =
10-
'postgres://localhost:5432/parse_server_postgres_adapter_test_database';
3+
const Config = require('../lib/Config');
114
const Parse = require('parse/node');
125
const request = require('../lib/request');
136
let databaseAdapter;
147

158
const fullTextHelper = () => {
16-
if (process.env.PARSE_SERVER_TEST_DB === 'postgres') {
17-
if (!databaseAdapter) {
18-
databaseAdapter = new PostgresStorageAdapter({ uri: postgresURI });
19-
}
20-
} else {
21-
databaseAdapter = new MongoStorageAdapter({ uri: mongoURI });
22-
}
9+
const config = Config.get('test');
10+
databaseAdapter = config.database.adapter;
11+
2312
const subjects = [
2413
'coffee',
2514
'Coffee Shopping',

spec/PostgresInitOptions.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const Parse = require('parse/node').Parse;
22
const PostgresStorageAdapter = require('../lib/Adapters/Storage/Postgres/PostgresStorageAdapter')
33
.default;
44
const postgresURI =
5+
process.env.PARSE_SERVER_TEST_DATABASE_URI ||
56
'postgres://localhost:5432/parse_server_postgres_adapter_test_database';
67
const ParseServer = require('../lib/index');
78
const express = require('express');

spec/PostgresStorageAdapter.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const PostgresStorageAdapter = require('../lib/Adapters/Storage/Postgres/PostgresStorageAdapter')
22
.default;
33
const databaseURI =
4+
process.env.PARSE_SERVER_TEST_DATABASE_URI ||
45
'postgres://localhost:5432/parse_server_postgres_adapter_test_database';
56
const Config = require('../lib/Config');
67

0 commit comments

Comments
 (0)