Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
Signed-off-by: Sumit Jaiswal <[email protected]>
  • Loading branch information
Sumit Jaiswal committed Aug 14, 2024
1 parent e02ee26 commit 7dbc8bb
Show file tree
Hide file tree
Showing 88 changed files with 19,717 additions and 605 deletions.
2 changes: 1 addition & 1 deletion .github/composite-actions/install-extensions/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ inputs:
migration_mode:
description: 'Database migration mode'
required: no
default: "single-db"
default: "multi-db"
parallel_query_mode:
description: 'Postgres Parallel Query Mode'
required: no
Expand Down
12 changes: 11 additions & 1 deletion .github/composite-actions/run-jdbc-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ inputs:
description: 'Test input directory'
required: no
default: input
migration_mode:
description: 'Database migration mode'
required: no
default: "multi-db"

runs:
using: "composite"
Expand All @@ -16,5 +20,11 @@ runs:
export PG_SRC=~/work/babelfish_extensions/postgresql_modified_for_babelfish
export inputFilesPath=${{inputs.input_dir}}
cd test/JDBC/
mvn test
if [[ '${{ inputs.migration_mode }}' == 'single-db' ]];then
export isSingleDbMode=true
mvn test
unset isSingleDbMode
else
mvn test
fi
shell: bash
2 changes: 1 addition & 1 deletion .github/composite-actions/run-pg-upgrade/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ inputs:
migration_mode:
description: 'Database migration mode'
required: no
default: 'single-db'
default: 'multi-db'
pg_old_dir:
description: "Previous postgres intall directory"
required: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
if: always() && steps.install-extensions.outcome == 'success'
run: |
sudo ~/psql/bin/psql -d postgres -U runner -v user="jdbc_user" -v db="jdbc_testdb" -f .github/scripts/cleanup_babelfish_database.sql
sudo ~/psql/bin/psql -v ON_ERROR_STOP=1 -d postgres -U runner -v user="jdbc_user" -v db="jdbc_testdb" -v migration_mode="single-db" -v tsql_port=1433 -v parallel_query_mode=false -f .github/scripts/create_extension.sql
sudo ~/psql/bin/psql -v ON_ERROR_STOP=1 -d postgres -U runner -v user="jdbc_user" -v db="jdbc_testdb" -v migration_mode="multi-db" -v tsql_port=1433 -v parallel_query_mode=false -f .github/scripts/create_extension.sql
sqlcmd -S localhost -U "jdbc_user" -P 12345678 -Q "SELECT @@version GO"
- name: Run Python Tests
Expand Down
174 changes: 174 additions & 0 deletions .github/workflows/jdbc-tests-multi-db-mode.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
name: JDBC Tests for multi-db mode
on: [push, pull_request]

jobs:
run-babelfish-jdbc-tests:
env:
INSTALL_DIR: psql
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
id: checkout

- name: Install Dependencies
id: install-dependencies
if: always()
uses: ./.github/composite-actions/install-dependencies

- name: Build Modified Postgres
id: build-modified-postgres
if: always() && steps.install-dependencies.outcome == 'success'
uses: ./.github/composite-actions/build-modified-postgres
with:
install_dir: 'psql'
code_coverage: 'yes'

- name: Compile ANTLR
id: compile-antlr
if: always() && steps.build-modified-postgres.outcome == 'success'
uses: ./.github/composite-actions/compile-antlr

- name: Build Extensions
id: build-extensions
if: always() && steps.compile-antlr.outcome == 'success'
uses: ./.github/composite-actions/build-extensions

- name: Build tds_fdw Extension
id: build-tds_fdw-extension
if: always() && steps.build-extensions.outcome == 'success'
uses: ./.github/composite-actions/build-tds_fdw-extension

- name: Build vector Extension
id: build-vector-extension
if: always() && steps.build-tds_fdw-extension.outcome == 'success'
uses: ./.github/composite-actions/build-vector-extension

- name: Build PostGIS Extension
id: build-postgis-extension
if: always() && steps.build-vector-extension.outcome == 'success'
uses: ./.github/composite-actions/build-postgis-extension

- name: Install Extensions
id: install-extensions
if: always() && steps.build-postgis-extension.outcome == 'success'
uses: ./.github/composite-actions/install-extensions
with:
wal_level: logical

- name: Run JDBC Tests
id: jdbc
if: always() && steps.install-extensions.outcome == 'success'
timeout-minutes: 60
uses: ./.github/composite-actions/run-jdbc-tests

- name: Start secondary server
id: start-secondary
if: always() && steps.jdbc.outcome == 'success'
uses: ./.github/composite-actions/install-extensions
with:
psql_port: 5433
tsql_port: 8199
wal_level: logical

- name: Setup Publication and Subscription
id: setup-pub-sub
if: always() && steps.start-secondary.outcome == 'success'
run: |
~/${{env.INSTALL_DIR}}/bin/psql -v ON_ERROR_STOP=1 -d jdbc_testdb -U runner -c "CREATE PUBLICATION my_pub;"
~/${{env.INSTALL_DIR}}/bin/psql -v ON_ERROR_STOP=1 -d jdbc_testdb -U runner -p 5433 -c "CREATE SUBSCRIPTION my_sub CONNECTION 'host=localhost port=5432 user=jdbc_user dbname=jdbc_testdb password=12345678' PUBLICATION my_pub;"
- name: Run Replication Tests
id: replication
if: always() && steps.setup-pub-sub.outcome == 'success'
timeout-minutes: 60
uses: ./.github/composite-actions/run-jdbc-tests
with:
input_dir: 'replication'

- name: Cleanup babelfish database
id: cleanup
if: always() && steps.replication.outcome == 'success'
run: |
sudo ~/psql/bin/psql -d postgres -U runner -v user="jdbc_user" -v db="jdbc_testdb" -f .github/scripts/cleanup_babelfish_database.sql
- name: Upload Log
if: always() && (steps.jdbc.outcome == 'failure' || steps.replication.outcome == 'failure')
uses: actions/upload-artifact@v2
with:
name: postgres-log-jdbc
path: |
~/psql/data/logfile
~/psql/data_5433/logfile
# The test summary files contain paths with ':' characters, which is not allowed with the upload-artifact actions
- name: Rename Test Summary Files
id: test-file-rename
if: always() && (steps.jdbc.outcome == 'failure' || steps.replication.outcome == 'failure')
run: |
cd test/JDBC/Info
timestamp=`ls -Art | tail -n 1`
cd $timestamp
mv $timestamp.diff ../output-diff.diff
mv "$timestamp"_runSummary.log ../run-summary.log
cd ..
# get the replication output diff as well if it is present
dir_count=`ls | wc -l`
if [[ $dir_count -eq 2 ]];then
timestamp=`ls -rt | tail -n 2 | sort -r | tail -n 1`
cd $timestamp
mv $timestamp.diff ../replication-output-diff.diff
mv "$timestamp"_runSummary.log ../replication-run-summary.log
- name: Upload Run Summary
if: always() && steps.test-file-rename.outcome == 'success'
uses: actions/upload-artifact@v2
with:
name: run-summary.log
path: |
test/JDBC/Info/run-summary.log
test/JDBC/Info/replication-run-summary.log
- name: Upload Output Diff
if: always() && (steps.jdbc.outcome == 'failure' || steps.replication.outcome == 'failure')
uses: actions/upload-artifact@v2
with:
name: jdbc-output-diff.diff
path: |
test/JDBC/Info/output-diff.diff
test/JDBC/Info/replication-output-diff.diff
- name: Check and upload coredumps
if: always() && (steps.jdbc.outcome == 'failure' || steps.replication.outcome == 'failure')
uses: ./.github/composite-actions/upload-coredump

- name: Generate Code Coverage
id: generate-code-coverage
if: always() && (steps.jdbc.outcome == 'success' && steps.replication.outcome == 'success')
run: |
export PG_CONFIG=~/psql/bin/pg_config
export PG_SRC=~/work/postgresql_modified_for_babelfish
export cmake=$(which cmake)
cd contrib
for ext in babelfishpg_common babelfishpg_money babelfishpg_tds babelfishpg_tsql
do
cd $ext
/usr/bin/lcov --gcov-tool /usr/bin/gcov -q --no-external -c -d . -d ./ -o lcov_test.info
cd ..
done
shell: bash

- name: Summarize code coverage
id: code-coverage-summary
if: always() && steps.generate-code-coverage.outcome == 'success'
run: |
cd contrib/
lcov -a babelfishpg_tsql/lcov_test.info -a babelfishpg_tds/lcov_test.info -a babelfishpg_common/lcov_test.info -a babelfishpg_money/lcov_test.info -o jdbc-lcov.info
lcov --list jdbc-lcov.info
- name: Upload Coverage Report for Babelfish Extensions
if: always() && steps.code-coverage-summary.outcome == 'success'
uses: actions/upload-artifact@v3
with:
name: coverage-babelfish-extensions-jdbc
path: contrib/jdbc-lcov.info
retention-days: 1
5 changes: 4 additions & 1 deletion .github/workflows/jdbc-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: JDBC Tests
name: JDBC Tests for single-db mode
on: [workflow_call]

jobs:
Expand Down Expand Up @@ -54,12 +54,15 @@ jobs:
uses: ./.github/composite-actions/install-extensions
with:
wal_level: logical
migration_mode: "single-db"

- name: Run JDBC Tests
id: jdbc
if: always() && steps.install-extensions.outcome == 'success'
timeout-minutes: 60
uses: ./.github/composite-actions/run-jdbc-tests
with:
migration_mode: "single-db"

- name: Start secondary server
id: start-secondary
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/major-version-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ jobs:
} > pg_hba.conf
~/${{env.OLD_INSTALL_DIR}}/bin/pg_ctl -c -D ~/${{env.OLD_INSTALL_DIR}}/data -l ~/${{env.OLD_INSTALL_DIR}}/data/logfile restart
cd ~/work/babelfish_extensions/babelfish_extensions/
sudo ~/${{env.OLD_INSTALL_DIR}}/bin/psql -v ON_ERROR_STOP=1 -d postgres -U runner -v user="jdbc_user" -v db="jdbc_testdb" -v migration_mode="single-db" -v tsql_port="1433" -f .github/scripts/create_extension.sql
sudo ~/${{env.OLD_INSTALL_DIR}}/bin/psql -v ON_ERROR_STOP=1 -d postgres -U runner -v user="jdbc_user" -v db="jdbc_testdb" -v migration_mode="multi-db" -v tsql_port="1433" -f .github/scripts/create_extension.sql
sqlcmd -S localhost -U jdbc_user -P 12345678 -Q "SELECT @@version GO"
shell: bash

Expand Down
60 changes: 34 additions & 26 deletions test/JDBC/expected/BABEL-1435.out
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,34 @@ GO
~~ERROR (Message: Database 'db1' already exists. Choose a different database name.)~~


-- single-db
SELECT COUNT(*) FROM pg_roles where rolname = 'dbo';
SELECT COUNT(*) FROM pg_roles where rolname = 'db_owner';
SELECT COUNT(*) FROM pg_namespace where nspname = 'dbo';
GO
~~START~~
int
0
~~END~~

~~START~~
int
0
~~END~~

~~START~~
int
0
~~END~~


-- multi-db
SELECT COUNT(*) FROM pg_roles where rolname = 'db1_dbo';
SELECT COUNT(*) FROM pg_roles where rolname = 'db1_db_owner';
SELECT COUNT(*) FROM pg_namespace where nspname = 'db1_dbo';
GO
~~START~~
int
1
~~END~~

Expand All @@ -120,12 +142,9 @@ int
~~END~~


-- should raise error in single-db
CREATE DATABASE db2;
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: Only one user database allowed under single-db mode. User database "db1" already exists)~~


USE db1;
GO
Expand All @@ -149,13 +168,9 @@ true
~~END~~


-- test error
-- should raise error in single-db
USE db2;
GO
~~ERROR (Code: 911)~~

~~ERROR (Message: database "db2" does not exist)~~


DROP DATABASE db1;
GO
Expand Down Expand Up @@ -184,19 +199,11 @@ int
~~END~~


-- test multi-db mode
SELECT set_config('babelfishpg_tsql.migration_mode', 'multi-db', false);
GO
~~START~~
text
multi-db
~~END~~


SELECT name FROM sys.sysdatabases ORDER BY name;
GO
~~START~~
text
db2
master
msdb
tempdb
Expand All @@ -216,6 +223,10 @@ GO

CREATE DATABASE db2;
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: Database 'db2' already exists. Choose a different database name.)~~


SELECT COUNT(*) FROM pg_roles where rolname = 'db1_dbo';
SELECT COUNT(*) FROM pg_roles where rolname = 'db1_db_owner';
Expand Down Expand Up @@ -262,21 +273,18 @@ GO

DROP DATABASE db2;
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: Cannot drop database "db2" because it is currently in use)~~


SELECT name FROM sys.sysdatabases ORDER BY name;
GO
~~START~~
text
db2
master
msdb
tempdb
~~END~~


SELECT set_config('babelfishpg_tsql.migration_mode', 'single-db', false);
GO
~~START~~
text
single-db
~~END~~

Loading

0 comments on commit 7dbc8bb

Please sign in to comment.