回歸測試是一個用于驗證PostgreSQL在你的系統(tǒng)上是否按照開發(fā)人員設想的那樣運行的測試套件,是PostgreSQL的測試方法之一。
回歸測試,需要事先定義好測試腳本(通常是SQL腳本,放在sql目錄中),同時定義好調用執(zhí)行測試腳本的預期正確輸出文件(通常放在expected目錄中)。
測試使用make check或make installcheck進行,它會通過pg_regress程序調用sql目錄中的SQL,并收集輸出結果(通常放到results目錄中),最后pg_regress會對expected目錄和results目錄中的文件使用diff進行一一比較。
如果比較發(fā)現(xiàn)文件內容不一致,會將不一致的結果輸出到result/results目錄下的regression.diffs文件中,并返回這個TEST CASE failed。
下面介紹兩種執(zhí)行的方式。
一、編譯源碼并進行測試
1、因PG不能在root用戶啟動,編譯時不能用root用戶編譯,否則很多目錄數(shù)據(jù)庫用戶沒有權限;
2、安裝編譯相關組件
/* 1. 安裝編譯工具gcc*/
# yum install gcc
/* 2. 安裝wget */
# yum install wget
/* 3. 安裝rpm打包工具rpm-build */
# yum install rpm-build
/* 4. 安裝postgresql編譯依賴組件 */
# yum install bison flex perl-ExtUtils-Embed perl python-devel tcl-devel readline-devel openssl-devel krb5-devel e2fsprogs-devel libxml2-devel libxslt-devel pam-devel libuuid-devel openldap-devel openjade opensp docbook-dtds
# yum install libicu-devel gettext
/* 5. centos 7 下編譯,需要安裝systemd-devel */
# yum install systemd-devel
3、編譯源碼:
export PGHOME=/home/appusr/PostgreSQL/pgsql-10
注:PGHOME為PostgreSQL的安裝路徑。
CenOS7如下:
./configure --enable-rpath --prefix=$PGHOME --includedir=$PGHOME/include --mandir=$PGHOME/share/man --datadir=$PGHOME/share --with-icu --with-perl --with-python --with-tcl --with-tclconfig=/usr/lib64 --with-openssl --with-pam --with-gssapi --with-includes=/usr/include --with-libraries=/usr/lib64 --enable-nls --enable-dtrace --with-uuid=e2fs --with-libxml --with-libxslt --with-ldap --with-selinux --with-systemd --docdir=$PGHOME/doc --htmldir=$PGHOME/doc/html --enable-debug
CenOS6如下:
./configure --enable-rpath --prefix=$PGHOME --includedir=$PGHOME/include --mandir=$PGHOME/share/man --datadir=$PGHOME/share --with-perl --with-python --with-tcl --with-tclconfig=/usr/lib64 --with-openssl --with-pam --with-gssapi --with-includes=/usr/include --with-libraries=/usr/lib64 --enable-nls --with-uuid=e2fs --with-libxml --with-libxslt --with-ldap --docdir=$PGHOME/doc --htmldir=$PGHOME/doc/html --enable-debug
make -j4 all
4、執(zhí)行regress測試工程代碼:
make -C /home/pg11/source/postgresql-11.1/src/test/regress check
二、安裝數(shù)據(jù)庫并進行測試
如果已經有數(shù)據(jù)庫的安裝包,可以直接進行安裝操作;如果需要在線下載安裝包的話,按如下方式執(zhí)行:
首先要保證機器能夠連接到網(wǎng)絡,然后執(zhí)行以下操作:
1)下載PostgreSQL:yum install -y https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-6-x86_64/pgdg-centos11-11-2.noarch.rpm
此命令下載的是PostgreSQL11,如要下載其他版本,可參考該連接:https://yum.postgresql.org/repopackages.php
2)下載測試所需要的組件:yum install postgresql11*
? ? ? 所有下載的組件都在目錄 /usr/pgsql-11 下
3)轉到目錄 /usr/pgsql-11/lib/test/regress 下,執(zhí)行以下語句即可:
? ? ./pg_regress --host=127.0.0.1 --port=5432 --user=test --inputdir=. --outputdir=. --schedule=serial_schedule
注意事項
如果使用臨時安裝(即編譯)的測試方式,pg的端口都是hard code的,使用前需要確認這些端口的占用情況。
如果使用已安裝的測試方式,測連接數(shù)據(jù)庫時,會使用coord的默認端口5432。所以必須使用默認安裝的數(shù)據(jù)庫集群才能使用已安裝方法的回歸測試。
自做成test case的方法
自做成test case的方法,可分為如下3步:
1、在sql/目錄下加入自做成的test? case的sql腳本。
2、在expected/目錄下加入自做成test case的sql腳本的正確結果。需要注意的是,由于判斷是使用diff命令,因此即使空格符也會導致diff的結果失敗。所以,做成expected目錄下的結果文件需要十分注意。
3、在parallel_schedule/ serial_schedule文件中添加調用sql腳本。