Skip to content

Commit

Permalink
Run Isolation tests as part of GitHub actions
Browse files Browse the repository at this point in the history
This framework will be able to:
1. Parse and understand PG isolation level test(.spec) file.
2. Maintain multiple connections and get their status: active, blocked(waiting
   for lock) or error.
3. Execute SQL commands on any connection without blocking the main thread and
   other connections.
4. Cancel or Terminate the test/SQL command in case some long running step or
   deadlock condition is encountered.
5. Generate an output file with SQL results and compare it with expected file
   provided.

Above functionality will ensure that it’ll be able to test isolation behaviour.

Added tests for foreign key related isolation tests : fk-contention and
fk-deadlock

Task:BABEL-2836,2021
Author: Harsh Lunagariya lunharsh@amazon.com
Signed-off-by: Harsh Lunagariya lunharsh@amazon.com
  • Loading branch information
HarshLunagariya authored and nasbyj committed Mar 29, 2022
1 parent 5cdc4e7 commit 2d70e54
Show file tree
Hide file tree
Showing 21 changed files with 1,086 additions and 7 deletions.
104 changes: 104 additions & 0 deletions .github/workflows/isolation-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Babelfish Smoke Tests
on:
push:
branches:
pull_request:
branches:

jobs:
isolation-tests:
name: Isolation-Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Clone, build, and run tests for Postgres engine
run: |
cd ..
git clone https://github.com/babelfish-for-postgresql/postgresql_modified_for_babelfish.git
sudo apt-get update
sudo apt-get install uuid-dev openjdk-8-jre libicu-dev libxml2-dev openssl libssl-dev python-dev libossp-uuid-dev libpq-dev cmake pkg-config g++ build-essential bison
cd postgresql_modified_for_babelfish
./configure --prefix=$HOME/postgres/ --with-python PYTHON=/usr/bin/python2.7 --enable-debug CFLAGS="-ggdb" --with-libxml --with-uuid=ossp --with-icu
make -j 4 2>error.txt
make install
cd contrib && make && sudo make install
- name: Copy ANTLR jar file
run: |
cd contrib/babelfishpg_tsql/antlr/thirdparty/antlr/
sudo cp antlr-4.9.3-complete.jar /usr/local/lib
- name: Compile ANTLR
run: |
cd ..
wget http://www.antlr.org/download/antlr4-cpp-runtime-4.9.3-source.zip
unzip -d antlr4 antlr4-cpp-runtime-4.9.3-source.zip
cd antlr4
mkdir build && cd build
cmake .. -D ANTLR_JAR_LOCATION=/usr/local/lib/antlr-4.9.3-complete.jar -DCMAKE_INSTALL_PREFIX=/usr/local -DWITH_DEMO=True
make
sudo make install
cp /usr/local/lib/libantlr4-runtime.so.4.9.3 ~/postgres/lib/
- name: Set env variables and build extensions
run: |
export PG_CONFIG=~/postgres/bin/pg_config
export PG_SRC=~/work/babelfish_extensions/postgresql_modified_for_babelfish
export cmake=$(which cmake)
cd contrib/babelfishpg_money
make && make install
cd ../babelfishpg_common
make && make install
cd ../babelfishpg_tds
make && make install
cd ../babelfishpg_tsql
make && make install
- name: Install extensions
run: |
cd ~
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
sudo apt-get update
sudo apt-get install -y mssql-tools unixodbc-dev
export PATH=/opt/mssql-tools/bin:$PATH
~/postgres/bin/initdb -D ~/postgres/data/
~/postgres/bin/pg_ctl -D ~/postgres/data/ -l logfile start
cd postgres/data
sudo sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/g" postgresql.conf
sudo sed -i "s/#shared_preload_libraries = ''/shared_preload_libraries = 'babelfishpg_tds'/g" postgresql.conf
ipaddress=$(ifconfig eth0 | grep 'inet ' | cut -d: -f2 | awk '{ print $2}')
sudo echo "host all all $ipaddress/32 trust" >> pg_hba.conf
~/postgres/bin/pg_ctl -D ~/postgres/data/ -l logfile restart
cd ~/work/babelfish_extensions/babelfish_extensions/
sudo ~/postgres/bin/psql -d postgres -U runner -v user="python_user" -v db="python_testdb" -f .github/scripts/create_extension.sql
sqlcmd -S localhost -U python_user -P 12345678 -Q "SELECT @@version GO"
- name: Install Python
uses: actions/setup-python@v2
with:
python-version: 3.7
- name: Configure Python environment
run: |
cd ~
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
cd ~/work/babelfish_extensions/babelfish_extensions/test/python
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql17 python3-dev
pip3 install pyodbc pymssql pytest pytest-xdist antlr4-python3-runtime
- name: Generate .spec file parser
run: |
cd ~/work/babelfish_extensions/babelfish_extensions/test/python/isolationtest/
java -Xmx500M -cp /usr/local/lib/antlr-4.9.3-complete.jar org.antlr.v4.Tool -Dlanguage=Python3 ./parser/*.g4 -visitor -no-listener
- name: Run Isolation tests
run: |
cd test/python
compareWithFile=true \
driver=pyodbc \
runInParallel=false \
testName=all \
provider="ODBC Driver 17 for SQL Server" \
fileGenerator_URL=localhost \
fileGenerator_port=1433 \
fileGenerator_databaseName=master \
fileGenerator_user=python_user \
fileGenerator_password=12345678 \
inputFilesPath=./input/isolation \
runIsolationTests=true \
stepTimeLimit=30 \
pytest -s --tb=long -q .
5 changes: 5 additions & 0 deletions test/python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore everything in the following directories except .gitkeep
/output/*/*
/logs/*
!/**/.gitkeep

6 changes: 6 additions & 0 deletions test/python/batch_run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from utils.config import config_dict as cfg
from execute_query import parse_prepared_statement, parse_stored_procedures, process_transaction_statement,process_statement_in_file_mode
from python_authentication import py_authentication
if cfg['runIsolationTests'] == 'true':
from isolationtest.isolationTestHandler import isolationTestHandler
import os


Expand Down Expand Up @@ -86,6 +89,9 @@ def batch_run(bbl_cnxn, file_handler, file, logger):
else:
failed += 1

elif f_type == "spec":
flag = isolationTestHandler(file ,file_handler, logger)

return (passed, failed)


Expand Down
2 changes: 2 additions & 0 deletions test/python/compare_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def handle_exception_in_file(e, file_writer):
def process_multiple_resultsets(bbl_rs, file_writer, result_processed, result_set_exist):
#not possible initial value
count = -10
if(result_set_exist is None):
result_set_exist = (bbl_rs.description is not None)

while True:

Expand Down
12 changes: 11 additions & 1 deletion test/python/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fileGenerator_password =
# PATH TO INPUT TEST FILES FOLDER
inputFilesPath = ./input

# SPECIFY IF YOU WISH TO EXECUTE TEST FILES SEQUENTIALLY OR IN PARALLEL
# SPECIFY IF YOU WISH TO EXECUTE TEST FILES SEQUENTIALLY OR IN PARALLEL(FALSE FOR ISOLATION TESTS)
runInParallel = false

# SPECIFY IF YOU WISH TO PRINT ALL THE LOGS/DIFF TO CONSOLE
Expand All @@ -35,10 +35,20 @@ outputColumnName = false
# SPECIFY IF ERROR CODE SHOULD BE DISPLAYED IN OUTPUT FILE
outputErrorCode = true

############################ ALLOW TO RUN ISOLATION TESTS (IF TRUE THEN RUNS ALL THE .SPEC FILES FROM INPUT DIRECTORY OTHERWISE SKIP THEM) ##################################################
runIsolationTests = false

############################ MAX TIME LIMIT FOR SINGLE STEP QUERY EXECUTION IN SECONDS(FOR ISOLATION TESTS ONLY) ############################
stepTimeLimit = 30

############################################ WHICH TEST TO RUN ############################################

# SET AS "all" TO RUN ALL THE TESTS FOR THE INPUT FILES INSIDE DIRECTORY WHOSE PATH IS SPECIFIED BY
# "inputFilesPath" OR SET AS THE NAME OF THE QUERY FILE YOU WANT TO TEST/CREATE EXPECTED OUTCOME FOR
# MULTIPLE INPUT TETS FILE NAMES CAN BE GIVEN SEPARATED WITH A SEMICOLON AND NO SPACES
testName = all

########################################### WHICH TEST TO IGNORE ##########################################

# MULTIPLE INPUT TETS FILE NAMES CAN BE GIVEN SEPARATED WITH A SEMICOLON AND NO SPACES
ignoredTestName =
27 changes: 27 additions & 0 deletions test/python/expected/pyodbc/fk-contention.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

starting permutation : { ins com upd }
step ins: INSERT INTO bar VALUES (42);
~~ROW COUNT: 1~~

step com: COMMIT;
step upd: UPDATE foo SET b = 'Hello World';
~~ROW COUNT: 1~~


starting permutation : { ins upd com }
step ins: INSERT INTO bar VALUES (42);
~~ROW COUNT: 1~~

step upd: UPDATE foo SET b = 'Hello World';
~~ROW COUNT: 1~~

step com: COMMIT;

starting permutation : { upd ins com }
step upd: UPDATE foo SET b = 'Hello World';
~~ROW COUNT: 1~~

step ins: INSERT INTO bar VALUES (42);
~~ROW COUNT: 1~~

step com: COMMIT;
Loading

0 comments on commit 2d70e54

Please sign in to comment.