mirror of
https://github.com/processone/ejabberd.git
synced 2025-01-01 17:53:00 +01:00
Add ability to run tests on upgraded DB
To test update_sql operation and functionality of resulting DB: 1. Load original schema to DB 2. Set {update_sql, true} in suite.erl 3. Run tests
This commit is contained in:
parent
9398052b65
commit
56e974ab80
51
.github/workflows/ci.yml
vendored
51
.github/workflows/ci.yml
vendored
@ -62,19 +62,19 @@ jobs:
|
||||
run: |
|
||||
sudo systemctl start mysql.service
|
||||
sudo systemctl start postgresql.service
|
||||
mysql -u root -proot -e "CREATE DATABASE ejabberd_test;"
|
||||
mysql -u root -proot -e "CREATE USER 'ejabberd_test'@'localhost'
|
||||
IDENTIFIED BY 'ejabberd_test';"
|
||||
mysql -u root -proot -e "CREATE DATABASE ejabberd_test;"
|
||||
mysql -u root -proot -e "GRANT ALL ON ejabberd_test.*
|
||||
TO 'ejabberd_test'@'localhost';"
|
||||
mysql -u root -proot ejabberd_test < sql/mysql.sql
|
||||
mysql -u ejabberd_test -pejabberd_test ejabberd_test < sql/mysql.sql
|
||||
pg_isready
|
||||
sudo -u postgres psql -c "CREATE DATABASE ejabberd_test;"
|
||||
sudo -u postgres psql -c "CREATE USER ejabberd_test
|
||||
WITH PASSWORD 'ejabberd_test';"
|
||||
sudo -u postgres psql -c "CREATE DATABASE ejabberd_test;"
|
||||
sudo -u postgres psql ejabberd_test -f sql/pg.sql
|
||||
sudo -u postgres psql -c "GRANT ALL PRIVILEGES
|
||||
ON DATABASE ejabberd_test TO ejabberd_test;"
|
||||
PGPASSWORD="ejabberd_test" psql -h localhost -U ejabberd_test ejabberd_test -f sql/pg.sql
|
||||
sudo -u postgres psql ejabberd_test -c "GRANT ALL PRIVILEGES ON ALL
|
||||
TABLES IN SCHEMA public
|
||||
TO ejabberd_test;"
|
||||
@ -221,6 +221,42 @@ jobs:
|
||||
CTRUN=`ls -la _build/test/logs/last | sed 's|.*-> ||'`
|
||||
echo "::notice::View CT results: https://processone.github.io/ecil/logs/$CTRUN/"
|
||||
|
||||
- name: Check for changes to trigger schema upgrade test
|
||||
uses: dorny/paths-filter@v2
|
||||
id: filter
|
||||
with:
|
||||
filters: |
|
||||
sql:
|
||||
- 'sql/**'
|
||||
- 'src/mod_admin_update_sql.erl'
|
||||
|
||||
- name: Prepare for schema upgrade test
|
||||
id: prepupgradetest
|
||||
if: ${{ steps.filter.outputs.sql == 'true' }}
|
||||
run: |
|
||||
[[ -d logs ]] && rm -rf logs
|
||||
[[ -d _build/test/logs ]] && rm -rf _build/test/logs || true
|
||||
sed -i 's|update_sql, false|update_sql, true|g' test/suite.erl
|
||||
- name: Run tests on upgraded schema (mysql, pgsql)
|
||||
run: CT_BACKENDS=mysql,pgsql make test
|
||||
if: always() && steps.prepupgradetest.outcome != 'skipped'
|
||||
id: ctupgradedschema
|
||||
- name: Check results
|
||||
if: always() && steps.ctupgradedschema.outcome != 'skipped'
|
||||
run: |
|
||||
[[ -d _build ]] && ln -s _build/test/logs/last/ logs || true
|
||||
ln `find logs/ -name suite.log` logs/suite.log
|
||||
grep 'TEST COMPLETE' logs/suite.log
|
||||
grep -q 'TEST COMPLETE,.* 0 failed' logs/suite.log
|
||||
test $(find logs/ -empty -name error.log)
|
||||
- name: View logs failures
|
||||
if: failure() && steps.ctupgradedschema.outcome != 'skipped'
|
||||
run: |
|
||||
cat logs/suite.log | awk \
|
||||
'BEGIN{RS="\n=case";FS="\n"} /=result\s*failed/ {print "=case" $0}'
|
||||
find logs/ -name error.log -exec cat '{}' ';'
|
||||
find logs/ -name exunit.log -exec cat '{}' ';'
|
||||
|
||||
- name: Prepare new schema
|
||||
run: |
|
||||
[[ -d logs ]] && rm -rf logs
|
||||
@ -230,11 +266,11 @@ jobs:
|
||||
mysql -u root -proot -e "CREATE DATABASE ejabberd_test;"
|
||||
mysql -u root -proot -e "GRANT ALL ON ejabberd_test.*
|
||||
TO 'ejabberd_test'@'localhost';"
|
||||
mysql -u root -proot ejabberd_test < sql/mysql.new.sql
|
||||
mysql -u ejabberd_test -pejabberd_test ejabberd_test < sql/mysql.new.sql
|
||||
sudo -u postgres psql -c "CREATE DATABASE ejabberd_test;"
|
||||
sudo -u postgres psql ejabberd_test -f sql/pg.new.sql
|
||||
sudo -u postgres psql -c "GRANT ALL PRIVILEGES
|
||||
ON DATABASE ejabberd_test TO ejabberd_test;"
|
||||
PGPASSWORD="ejabberd_test" psql -h localhost -U ejabberd_test ejabberd_test -f sql/pg.new.sql
|
||||
sudo -u postgres psql ejabberd_test -c "GRANT ALL PRIVILEGES ON ALL
|
||||
TABLES IN SCHEMA public
|
||||
TO ejabberd_test;"
|
||||
@ -242,7 +278,8 @@ jobs:
|
||||
SEQUENCES IN SCHEMA public
|
||||
TO ejabberd_test;"
|
||||
sed -i 's|new_schema, false|new_schema, true|g' test/suite.erl
|
||||
- run: CT_BACKENDS=mysql,pgsql make test
|
||||
- name: Run tests on new schema (mysql, pgsql)
|
||||
run: CT_BACKENDS=mysql,pgsql make test
|
||||
id: ctnewschema
|
||||
- name: Check results
|
||||
if: always() && steps.ctnewschema.outcome != 'skipped'
|
||||
|
@ -34,6 +34,8 @@
|
||||
% Commands API
|
||||
-export([update_sql/0]).
|
||||
|
||||
% For testing
|
||||
-export([update_sql/1]).
|
||||
|
||||
-include("logger.hrl").
|
||||
-include("ejabberd_commands.hrl").
|
||||
|
@ -99,7 +99,8 @@ do_init_per_group(mysql, Config) ->
|
||||
case catch ejabberd_sql:sql_query(?MYSQL_VHOST, [<<"select 1;">>]) of
|
||||
{selected, _, _} ->
|
||||
mod_muc:shutdown_rooms(?MYSQL_VHOST),
|
||||
clear_sql_tables(mysql, ?config(base_dir, Config)),
|
||||
clear_sql_tables(mysql, Config),
|
||||
update_sql(?MYSQL_VHOST, Config),
|
||||
set_opt(server, ?MYSQL_VHOST, Config);
|
||||
Err ->
|
||||
{skip, {mysql_not_available, Err}}
|
||||
@ -108,7 +109,8 @@ do_init_per_group(mssql, Config) ->
|
||||
case catch ejabberd_sql:sql_query(?MSSQL_VHOST, [<<"select 1;">>]) of
|
||||
{selected, _, _} ->
|
||||
mod_muc:shutdown_rooms(?MSSQL_VHOST),
|
||||
clear_sql_tables(mssql, ?config(base_dir, Config)),
|
||||
clear_sql_tables(mssql, Config),
|
||||
update_sql(?MSSQL_VHOST, Config),
|
||||
set_opt(server, ?MSSQL_VHOST, Config);
|
||||
Err ->
|
||||
{skip, {mssql_not_available, Err}}
|
||||
@ -117,7 +119,8 @@ do_init_per_group(pgsql, Config) ->
|
||||
case catch ejabberd_sql:sql_query(?PGSQL_VHOST, [<<"select 1;">>]) of
|
||||
{selected, _, _} ->
|
||||
mod_muc:shutdown_rooms(?PGSQL_VHOST),
|
||||
clear_sql_tables(pgsql, ?config(base_dir, Config)),
|
||||
clear_sql_tables(pgsql, Config),
|
||||
update_sql(?PGSQL_VHOST, Config),
|
||||
set_opt(server, ?PGSQL_VHOST, Config);
|
||||
Err ->
|
||||
{skip, {pgsql_not_available, Err}}
|
||||
@ -1011,37 +1014,35 @@ bookmark_conference() ->
|
||||
'$handle_undefined_function'(_, _) ->
|
||||
erlang:error(undef).
|
||||
|
||||
|
||||
%%%===================================================================
|
||||
%%% SQL stuff
|
||||
%%%===================================================================
|
||||
clear_sql_tables(sqlite, _BaseDir) ->
|
||||
update_sql(Host, Config) ->
|
||||
case ?config(update_sql, Config) of
|
||||
true ->
|
||||
mod_admin_update_sql:update_sql(Host);
|
||||
false -> ok
|
||||
end.
|
||||
|
||||
schema_suffix(Config) ->
|
||||
case ejabberd_sql:use_new_schema() of
|
||||
true ->
|
||||
case ?config(update_sql, Config) of
|
||||
true -> ".sql";
|
||||
_ -> ".new.sql"
|
||||
end;
|
||||
_ -> ".sql"
|
||||
end.
|
||||
|
||||
clear_sql_tables(sqlite, _Config) ->
|
||||
ok;
|
||||
clear_sql_tables(Type, BaseDir) ->
|
||||
clear_sql_tables(Type, Config) ->
|
||||
BaseDir = ?config(base_dir, Config),
|
||||
{VHost, File} = case Type of
|
||||
mysql ->
|
||||
Path = case ejabberd_sql:use_new_schema() of
|
||||
true ->
|
||||
"mysql.new.sql";
|
||||
false ->
|
||||
"mysql.sql"
|
||||
end,
|
||||
{?MYSQL_VHOST, Path};
|
||||
mssql ->
|
||||
Path = case ejabberd_sql:use_new_schema() of
|
||||
true ->
|
||||
"mssql.new.sql";
|
||||
false ->
|
||||
"mssql.sql"
|
||||
end,
|
||||
{?MSSQL_VHOST, Path};
|
||||
pgsql ->
|
||||
Path = case ejabberd_sql:use_new_schema() of
|
||||
true ->
|
||||
"pg.new.sql";
|
||||
false ->
|
||||
"pg.sql"
|
||||
end,
|
||||
{?PGSQL_VHOST, Path}
|
||||
mysql -> {?MYSQL_VHOST, "mysql" ++ schema_suffix(Config)};
|
||||
mssql -> {?MSSQL_VHOST, "mssql" ++ schema_suffix(Config)};
|
||||
pgsql -> {?PGSQL_VHOST, "pg" ++ schema_suffix(Config)}
|
||||
end,
|
||||
SQLFile = filename:join([BaseDir, "sql", File]),
|
||||
CreationQueries = read_sql_queries(SQLFile),
|
||||
|
@ -108,6 +108,7 @@ max_fsm_queue: 1000
|
||||
queue_type: file
|
||||
modules:
|
||||
mod_adhoc: []
|
||||
mod_admin_update_sql: []
|
||||
mod_announce: []
|
||||
mod_configure: []
|
||||
mod_disco: []
|
||||
|
@ -131,6 +131,7 @@ init_config(Config) ->
|
||||
{resource, <<"resource!@#$%^&*()'\"`~<>+-/;:_=[]{}|\\">>},
|
||||
{master_resource, <<"master_resource!@#$%^&*()'\"`~<>+-/;:_=[]{}|\\">>},
|
||||
{slave_resource, <<"slave_resource!@#$%^&*()'\"`~<>+-/;:_=[]{}|\\">>},
|
||||
{update_sql, false},
|
||||
{password, Password},
|
||||
{backends, Backends}
|
||||
|Config].
|
||||
|
Loading…
Reference in New Issue
Block a user