Skip to content

Commit a632a69

Browse files
committed
MDEV-36127 Add MTR test for mariadb-upgrade-service on Windows
Added a test to verify mariadb-upgrade-service functionality on Windows. The test runs mariadb-install-db.exe to create a Windows service, then executes mariadb-upgrade-service.exe while the service is online or offline. There is no real cross-version upgrade in this test(not possible with MTR), the actual goal is just to run smoke-test. Last times mariadb-upgrade-service was broken (CONC-760, MDEV-30639) there were problems with named pipe connections, which could be detected and prevented by smoke-test alone.
1 parent fc60b89 commit a632a69

File tree

5 files changed

+164
-9
lines changed

5 files changed

+164
-9
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ IF(NOT WITHOUT_SERVER)
633633
perror
634634
replace)
635635
IF(WIN32)
636-
ADD_DEPENDENCIES(minbuild echo mariadb-install-db my_safe_kill)
636+
ADD_DEPENDENCIES(minbuild echo mariadb-install-db my_safe_kill mariadb-upgrade-service)
637637
ENDIF()
638638
ADD_CUSTOM_TARGET(smoketest
639639
COMMAND perl ./mysql-test-run.pl main.1st
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use mysql;
2+
# run mysql_install_db with --service parameter
3+
# Start service
4+
# -- Upgrade service (online) --
5+
Phase 1/10: Stopping service
6+
Phase 2/10: Start and stop server in the old version, to avoid crash recovery (skipped)
7+
Phase 3/10: Fixing server config file
8+
Phase 4/10: Starting mysqld for upgrade
9+
Phase 5/10: Waiting for startup to complete
10+
Phase 6/10: Running mysql_upgrade
11+
Phase 7/10: Changing service configuration
12+
Phase 8/10: Initiating server shutdown
13+
Phase 9/10: Waiting for shutdown to complete
14+
Phase 10/10: Starting service
15+
Service 'SERVICE_NAME' successfully upgraded.
16+
Log file is written to UPGRADE_LOG
17+
# upgrade_success(online)=1
18+
# Service stopped
19+
# -- Upgrade service (offline) --
20+
Phase 1/10: Stopping service
21+
Phase 2/10: Start and stop server in the old version, to avoid crash recovery ,this can take some time
22+
Phase 3/10: Fixing server config file
23+
Phase 4/10: Starting mysqld for upgrade
24+
Phase 5/10: Waiting for startup to complete
25+
Phase 6/10: Running mysql_upgrade
26+
Phase 7/10: Changing service configuration
27+
Phase 8/10: Initiating server shutdown
28+
Phase 9/10: Waiting for shutdown to complete
29+
Phase 10/10: Starting service (skipped)
30+
Service 'SERVICE_NAME' successfully upgraded.
31+
Log file is written to UPGRADE_LOG
32+
# upgrade_success(offline)=1
33+
# Delete service
34+
connection default;
35+
# restart
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
source include/windows.inc;
2+
let $datadir_name=data;
3+
let $service_name_prefix=mariadb;
4+
let $password=password;
5+
6+
source include/check_windows_admin.inc;
7+
8+
# The test uses return code from sc.exe utility, which are as follows
9+
let $ERROR_SERVICE_DOES_NOT_EXIST= 1060;
10+
let $ERROR_SERVICE_CANNOT_ACCEPT_CTRL=1061;# intermediate, during start or stop
11+
let $ERROR_SERVICE_NOT_ACTIVE=1062;# service stopped
12+
let $ERROR_INVALID_SERVICE_CONTROL=1052; # The requested control is not valid for this service
13+
14+
let $sc_exe= C:\Windows\System32\sc.exe;
15+
let $ddir= $MYSQLTEST_VARDIR/tmp/$datadir_name;
16+
let $service_name=$service_name_prefix$MASTER_MYPORT;
17+
let TMP= $MYSQLTEST_VARDIR/tmp;
18+
let $upgrade_log=$TMP/mysql_upgrade_service.$service_name.log;
19+
20+
use mysql;
21+
error 0,1;
22+
rmdir $ddir;
23+
24+
--disable_result_log
25+
error 0,$ERROR_SERVICE_DOES_NOT_EXIST;
26+
exec $sc_exe delete $service_name;
27+
--enable_result_log
28+
29+
source include/shutdown_mysqld.inc;
30+
echo # run mysql_install_db with --service parameter;
31+
--disable_result_log
32+
exec $MYSQL_INSTALL_DB_EXE --datadir=$ddir --port=$MASTER_MYPORT --password=$password --service=$service_name --verbose-bootstrap -R;
33+
--enable_result_log
34+
35+
echo # Start service;
36+
--disable_result_log
37+
exec $sc_exe start $service_name;
38+
--enable_result_log
39+
40+
enable_reconnect;
41+
source include/wait_until_connected_again.inc;
42+
disable_reconnect;
43+
44+
echo # -- Upgrade service (online) --;
45+
--replace_result $upgrade_log UPGRADE_LOG $service_name SERVICE_NAME
46+
let $sys_errno=0;
47+
let $upgrade_success = 1;
48+
error 0,1;
49+
exec $MARIADB_UPGRADE_SERVICE_EXE --service=$service_name;
50+
51+
if($sys_errno != 0)
52+
{
53+
let $upgrade_success = 0;
54+
}
55+
56+
echo # upgrade_success(online)=$upgrade_success;
57+
file_exists $upgrade_log;
58+
if ($upgrade_success == 0)
59+
{
60+
echo --detailed error(online upgrade)--;
61+
cat_file $upgrade_log;
62+
}
63+
# stop service
64+
--disable_result_log
65+
# Wait until stopped
66+
let $sys_errno=0;
67+
while($sys_errno != $ERROR_SERVICE_NOT_ACTIVE)
68+
{
69+
--error 0,$ERROR_SERVICE_CANNOT_ACCEPT_CTRL,$ERROR_SERVICE_NOT_ACTIVE, $ERROR_INVALID_SERVICE_CONTROL
70+
exec $sc_exe stop $service_name;
71+
if($sys_errno != $ERROR_SERVICE_NOT_ACTIVE)
72+
{
73+
--real_sleep 0.1
74+
}
75+
}
76+
--enable_result_log
77+
echo # Service stopped;
78+
79+
echo # -- Upgrade service (offline) --;
80+
--replace_result $upgrade_log UPGRADE_LOG $service_name SERVICE_NAME
81+
let $sys_errno=0;
82+
let $upgrade_success = 1;
83+
error 0,1;
84+
exec $MARIADB_UPGRADE_SERVICE_EXE --service=$service_name;
85+
86+
if($sys_errno != 0)
87+
{
88+
let $upgrade_success = 0;
89+
}
90+
91+
echo # upgrade_success(offline)=$upgrade_success;
92+
file_exists $upgrade_log;
93+
if ($upgrade_success == 0)
94+
{
95+
echo --detailed error(online upgrade)--;
96+
cat_file $upgrade_log;
97+
}
98+
99+
echo # Delete service;
100+
let $sys_errno=0;
101+
--disable_result_log
102+
exec $sc_exe delete $service_name;
103+
--enable_result_log
104+
105+
# Cleanup
106+
source include/wait_until_disconnected.inc;
107+
rmdir $ddir;
108+
remove_file $upgrade_log;
109+
let TEMP=$old_temp;
110+
111+
#restart original server
112+
connection default;
113+
source include/start_mysqld.inc;

mysql-test/mariadb-test-run.pl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,6 +2226,9 @@ sub environment_setup {
22262226
{
22272227
$ENV{'MYSQL_INSTALL_DB_EXE'}= mtr_exe_exists("$bindir/sql$multiconfig/mariadb-install-db",
22282228
"$bindir/bin/mariadb-install-db");
2229+
$ENV{'MARIADB_UPGRADE_SERVICE_EXE'}= mtr_exe_exists("$bindir/sql$multiconfig/mariadb-upgrade-service",
2230+
"$bindir/bin/mariadb-upgrade-service");
2231+
$ENV{'MARIADB_UPGRADE_EXE'}= mtr_exe_exists("$path_client_bindir/mariadb-upgrade");
22292232
}
22302233

22312234
my $client_config_exe=

sql/mysql_upgrade_service.cc

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ extern int upgrade_config_file(const char *myini_path);
4545
"OPTIONS:"
4646

4747
static char mysqld_path[MAX_PATH];
48-
static char mysqladmin_path[MAX_PATH];
4948
static char mysqlupgrade_path[MAX_PATH];
5049

5150
static char defaults_file_param[MAX_PATH + 16]; /*--defaults-file=<path> */
@@ -455,8 +454,9 @@ int main(int argc, char **argv)
455454

456455
/*
457456
Get full path to mysqld, we need it when changing service configuration.
458-
Assume installation layout, i.e mysqld.exe, mysqladmin.exe, mysqlupgrade.exe
459-
and mysql_upgrade_service.exe are in the same directory.
457+
Assume mysqld.exe in the same directory as this program.
458+
mysql_upgrade.exe is either in the same directory, or pointed to by
459+
MARIADB_UPGRADE_EXE environment variable (in case of MTR running it)
460460
*/
461461
GetModuleFileName(NULL, bindir, FN_REFLEN);
462462
p= strrchr(bindir, FN_LIBCHAR);
@@ -465,15 +465,19 @@ int main(int argc, char **argv)
465465
*p= 0;
466466
}
467467
sprintf_s(mysqld_path, "%s\\mysqld.exe", bindir);
468-
sprintf_s(mysqladmin_path, "%s\\mysqladmin.exe", bindir);
469468
sprintf_s(mysqlupgrade_path, "%s\\mysql_upgrade.exe", bindir);
470469

471-
char *paths[]= {mysqld_path, mysqladmin_path, mysqlupgrade_path};
472-
for(int i= 0; i< 3;i++)
470+
if (access(mysqld_path, 0))
471+
die("File %s does not exist", mysqld_path);
472+
if (access(mysqlupgrade_path, 0))
473473
{
474-
if(GetFileAttributes(paths[i]) == INVALID_FILE_ATTRIBUTES)
475-
die("File %s does not exist", paths[i]);
474+
/* Try to get path from environment variable, set by MTR */
475+
char *alt_mysqlupgrade_path= getenv("MARIADB_UPGRADE_EXE");
476+
if (alt_mysqlupgrade_path)
477+
sprintf_s(mysqlupgrade_path, "%s", alt_mysqlupgrade_path);
476478
}
479+
if (access(mysqlupgrade_path, 0))
480+
die("File %s does not exist", mysqld_path);
477481

478482
/*
479483
Messages written on stdout should not be buffered, GUI upgrade program

0 commit comments

Comments
 (0)