Skip to content

Commit 78f031b

Browse files
authored
Merge pull request #213 from choroba/mysql8
Update CI, fix Embedded server, improve tests, adjust to MySQL 8
2 parents 69a5d5f + 0ea6902 commit 78f031b

18 files changed

+445
-159
lines changed

.github/workflows/ci.yaml

Lines changed: 135 additions & 62 deletions
Large diffs are not rendered by default.

Makefile.PL

Lines changed: 120 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,22 @@ push @mysql_headers, 'mysql.h';
2424

2525
our $opt = { "help" => \&Usage, };
2626

27-
my ($test_host, $test_port, $test_socket, $test_authplugin);
27+
my ($test_host, $test_port, $test_socket, $test_embdatadir);
2828
{
29-
local ($::test_host, $::test_port, $::test_user, $::test_socket, $::test_authplugin, $::test_password, $::test_db, $::test_mysql_config, $::test_cflags, $::test_libs);
29+
local ($::test_host, $::test_port, $::test_user, $::test_socket, $::test_embdatadir, $::test_emboptions, $::test_authplugin, $::test_password, $::test_db, $::test_mysql_config, $::test_cflags, $::test_libs);
3030
eval { require "./t/MariaDB.mtest" } and do {
3131
$opt->{'testuser'} = $::test_user;
3232
$opt->{'testpassword'} = $::test_password;
3333
$opt->{'testdb'} = $::test_db;
3434
$opt->{'mysql_config'} = $::test_mysql_config;
3535
$opt->{'cflags'} = $::test_cflags;
3636
$opt->{'libs'} = $::test_libs;
37+
$opt->{'testemboptions'} = $::test_emboptions;
38+
$opt->{'testauthplugin'} = $::test_authplugin;
3739
$test_host = $::test_host;
3840
$test_port = $::test_port;
3941
$test_socket = $::test_socket;
40-
$test_authplugin = $::test_authplugin;
42+
$test_embdatadir = $::test_embdatadir;
4143
}
4244
}
4345

@@ -50,7 +52,10 @@ Getopt::Long::GetOptions(
5052
"testuser:s",
5153
"testpassword:s",
5254
"testsocket:s",
55+
"testembdatadir:s",
56+
"testemboptions:s",
5357
"testauthplugin:s",
58+
"requireembsup!",
5459
"cflags:s",
5560
"libs:s",
5661
"mysql_config:s",
@@ -106,62 +111,112 @@ MSG
106111
}
107112
}
108113

109-
for my $key (qw(testdb testhost testuser testpassword testsocket testauthplugin testport cflags libs))
114+
if (exists $opt->{requireembsup})
115+
{
116+
$source->{'requireembsup'} = "User's choice";
117+
}
118+
elsif (defined $ENV{'DBD_MARIADB_REQUIREEMBSUP'})
119+
{
120+
$source->{'requireembsup'} = 'environment';
121+
$opt->{'requireembsup'} = !!$ENV{DBD_MARIADB_REQUIREEMBSUP};
122+
}
123+
else
124+
{
125+
$source->{'requireembsup'} = 'default';
126+
$opt->{'requireembsup'} = 0;
127+
}
128+
129+
for my $key (qw(testdb testhost testuser testpassword testsocket testport testembdatadir testemboptions testauthplugin cflags libs))
110130
{
111131
Configure($opt, $source, $key);
112132
}
113133

114-
if (!$opt->{testport} && (!$opt->{testhost} || $opt->{testhost} eq 'localhost') && !defined $opt->{testsocket} && $test_socket) {
134+
# Reusing old test host is possible if it does not conflict with new test port, new test socket or new test embdatadir
135+
if (!defined $opt->{testhost} && defined $test_host && length $test_host &&
136+
((defined $opt->{testport} && $test_host ne 'localhost' && $test_host ne 'embedded') ||
137+
(defined $opt->{testsocket} && $test_host eq 'localhost') ||
138+
(defined $opt->{testembdatadir} && $test_host eq 'embedded') ||
139+
(!defined $opt->{testsocket} && !defined $opt->{testembdatadir} && !defined $opt->{testport}))) {
140+
$opt->{testhost} = $test_host;
141+
$source->{testhost} = "User's choice";
142+
}
143+
144+
# Reusing old test port is possible if it does not conflict with new test host, new test socket or new test embdatadir
145+
if (!defined $opt->{testport} && defined $test_port && length $test_port &&
146+
(!defined $opt->{testhost} || ($opt->{testhost} ne 'localhost' && $opt->{testhost} ne 'embedded')) &&
147+
!defined $opt->{testsocket} &&
148+
!defined $opt->{testembdatadir}) {
149+
$opt->{testport} = $test_port;
150+
$source->{testport} = "User's choice";
151+
}
152+
153+
# Reusing old test socket is possible if it does not conflict with new test host, new test port or new test embdatadir
154+
if (!defined $opt->{testsocket} && defined $test_socket && length $test_socket &&
155+
(!defined $opt->{testhost} || $opt->{testhost} eq 'localhost') &&
156+
!defined $opt->{testport} &&
157+
!defined $opt->{testembdatadir}) {
115158
$opt->{testsocket} = $test_socket;
116159
$source->{testsocket} = "User's choice";
117160
}
118161

119-
if (!$opt->{testsocket}) {
120-
if (!defined $opt->{testhost} && $test_host && (!$opt->{testport} || $test_host ne 'localhost')) {
121-
$opt->{testhost} = $test_host;
122-
$source->{testhost} = "User's choice";
123-
}
124-
if (!defined $opt->{testport} && $test_port && (!$opt->{testhost} || $opt->{testhost} ne 'localhost')) {
125-
$opt->{testport} = $test_port;
126-
$source->{testport} = "User's choice";
127-
}
128-
} else {
129-
if (!defined $opt->{testhost} && $test_host && $test_host eq 'localhost') {
130-
$opt->{testhost} = 'localhost';
131-
$source->{testhost} = "User's choice";
132-
}
162+
# Reusing old test embdatadir is possible if it does not conflict with new test host, new test port or new test socket
163+
if (!defined $opt->{testembdatadir} && defined $test_embdatadir && length $test_embdatadir &&
164+
(!defined $opt->{testhost} || $opt->{testhost} eq 'embedded') &&
165+
!defined $opt->{testport} &&
166+
!defined $opt->{testsocket}) {
167+
$opt->{testembdatadir} = $test_embdatadir;
168+
$source->{testembdatadir} = "User's choice";
169+
}
170+
171+
# if we have a testsocket but no host, set localhost
172+
if (defined $opt->{testsocket} && !defined $opt->{testhost}) {
173+
$opt->{testhost} = 'localhost';
174+
$source->{testhost} = 'guessed';
133175
}
134176

135-
#if we have a testport but no host, assume 127.0.0.1
136-
if ( $opt->{testport} && !$opt->{testhost} ) {
177+
# if we have a testembdatadir but no host, set embedded
178+
if (defined $opt->{testembdatadir} && !defined $opt->{testhost}) {
179+
$opt->{testhost} = 'embedded';
180+
$source->{testhost} = 'guessed';
181+
}
182+
183+
# if we have a testport but no host, assume 127.0.0.1
184+
if (defined $opt->{testport} && !defined $opt->{testhost}) {
137185
$opt->{testhost} = '127.0.0.1';
138186
$source->{testhost} = 'guessed';
139187
}
140188

141-
foreach (qw(testhost testport testsocket testauthplugin)) {
189+
foreach (qw(testhost testport testsocket testembdatadir)) {
142190
next if defined $opt->{$_};
143191
$opt->{$_} = '';
144192
$source->{$_} = 'default';
145193
}
146194

147195
# testsocket makes sense only when testhost is localhost
148-
if ($opt->{testsocket} && $opt->{testhost} && $opt->{testhost} ne 'localhost') {
196+
if (length $opt->{testsocket} && $opt->{testhost} ne 'localhost') {
149197
die << "MSG";
150-
Option --testport or --testhost different from localhost cannot be specified together with option --testsocket.
198+
Option --testhost different from localhost cannot be specified together with option --testsocket.
151199
MSG
152200
}
153201

154-
# testport cannot be specified when host is localhost
155-
if ($opt->{testport} && $opt->{testhost} && $opt->{testhost} eq 'localhost') {
202+
# testembdatadir makes sense only when testhost is embedded
203+
if (length $opt->{testembdatadir} && $opt->{testhost} ne 'embedded') {
156204
die << "MSG";
157-
Option --testport cannot be specified when --testhost is localhost.
205+
Option --testhost different from embedded cannot be specified together with option --testembdatadir.
158206
MSG
159207
}
160208

161-
# testhost cannot be embedded
162-
if ($opt->{testhost} && $opt->{testhost} eq 'embedded') {
209+
# there is no default testembdatadir, so check that it is set
210+
if ($opt->{testhost} eq 'embedded' && !length $opt->{testembdatadir}) {
163211
die << "MSG";
164-
Option --testhost cannot be embedded.
212+
Option --testembdatadir must be specified when --testhost is embedded.
213+
MSG
214+
}
215+
216+
# testport cannot be specified when host is localhost or embedded
217+
if (length $opt->{testport} && ($opt->{testhost} eq 'localhost' || $opt->{testhost} eq 'embedded')) {
218+
die << "MSG";
219+
Option --testport cannot be specified when --testhost is localhost or embedded.
165220
MSG
166221
}
167222

@@ -262,6 +317,14 @@ my $have_embedded = check_lib(
262317

263318
print "Embedded server: " . ($have_embedded ? "supported" : "not supported by client library") . "\n\n";
264319

320+
if (!$have_embedded && ($opt->{testhost} eq 'embedded' || $opt->{requireembsup})) {
321+
die << "MSG";
322+
Cannot run test suite against Embedded server (specified via
323+
option --testhost=embedded or option --requireembsup) because
324+
Embedded server is not supported by client library.
325+
MSG
326+
}
327+
265328
my $have_get_charset_number = check_lib(
266329
LIBS => (join ' ', @libdirs, $main_lib),
267330
ccflags => $opt->{cflags},
@@ -414,20 +477,26 @@ EOF
414477
print "Client library deinitialize OpenSSL library functions: " . ($have_problem_with_openssl ? "yes" : "no") . "\n\n";
415478

416479
my $fileName = File::Spec->catfile("t", "MariaDB.mtest");
480+
print "Writing $fileName for test suite\n";
417481
(open(FILE, ">$fileName") &&
418-
(print FILE ("{ local " . Data::Dumper->Dump([$opt], ["opt"]) .
419-
" local " . Data::Dumper->Dump([$source], ["source"]) .
482+
(print FILE ("{\n" .
483+
"local " . Data::Dumper->new([$opt], ["opt"])->Sortkeys(1)->Indent(1)->Dump() .
484+
"local " . Data::Dumper->new([$source], ["source"])->Sortkeys(1)->Indent(1)->Dump() .
420485
"\$::test_host = \$opt->{'testhost'};\n" .
421486
"\$::test_port = \$opt->{'testport'};\n" .
422487
"\$::test_user = \$opt->{'testuser'};\n" .
423488
"\$::test_socket = \$opt->{'testsocket'};\n" .
489+
"\$::test_embdatadir = \$opt->{'testembdatadir'};\n" .
490+
"\$::test_emboptions = \$opt->{'testemboptions'};\n" .
424491
"\$::test_authplugin = \$opt->{'testauthplugin'};\n" .
425492
"\$::test_password = \$opt->{'testpassword'};\n" .
426493
"\$::test_db = \$opt->{'testdb'};\n" .
427494
"\$::test_dsn = \"DBI:MariaDB:\$::test_db\";\n" .
428495
"\$::test_dsn .= \":\$::test_host\" if \$::test_host;\n" .
429496
"\$::test_dsn .= \":\$::test_port\" if \$::test_port;\n".
430497
"\$::test_dsn .= \";mariadb_socket=\$::test_socket\" if \$::test_socket;\n" .
498+
"\$::test_dsn .= \";mariadb_embedded_options=--datadir=\$::test_embdatadir\" if \$::test_embdatadir;\n" .
499+
"\$::test_dsn .= \",\$::test_emboptions\" if \$::test_embdatadir and \$::test_emboptions;\n" .
431500
"\$::test_dsn .= \";mariadb_auth_plugin=\$::test_authplugin\" if \$::test_authplugin;\n" .
432501
"\$::test_dsn .= \";mariadb_connect_timeout=120;mariadb_read_timeout=120;mariadb_write_timeout=120\";\n" .
433502
"\$::test_mysql_config = \$opt->{'mysql_config'} if \$source->{'mysql_config'} eq 'User\\'s choice';\n" .
@@ -661,9 +730,19 @@ Possible options are:
661730
the database server; by default unix socket is chosen
662731
by mariadb/mysqlclient library; takes effect only
663732
when --testhost is set to "localhost"
733+
--testembdatadir=<dir> Use <dir> as database directory for embedded server,
734+
it may be and it is suggested to be empty, which means
735+
that database is uninitialized; takes effect only when
736+
--testhost is set to "embedded"
737+
--testemboptions=<op> Use <op> as additional options for embedded server
738+
separated by comma, it is recommended to set output
739+
log file (e.g. '--log-error=/dev/null') and language
740+
directory (e.g. '--language=/usr/local/share/mysql')
741+
if language directory is different than system one
664742
--testauthplugin=<ap> Use <ap> auth plugin when doing user authentication
665743
handshake with server; for older server versions it is
666744
needed to pass "mysql_native_password"
745+
--requireembsup Require client library with embedded server support
667746
--mariadb_config Synonym for --mysql_config, override it
668747
--mysql_config=<path> Specify <path> for mariadb_config or mysql_config script
669748
--help Print this message and exit
@@ -858,6 +937,14 @@ perl Makefile.PL --testuser=username
858937
$source->{$param} = "default";
859938
$opt->{$param} = "";
860939
}
940+
elsif ($param eq "testauthplugin") {
941+
$source->{$param} = "default";
942+
$opt->{$param} = "";
943+
}
944+
elsif ($param eq "testemboptions") {
945+
$source->{$param} = "default";
946+
$opt->{$param} = "";
947+
}
861948
elsif ($param eq "cflags") {
862949
$source->{$param} = "guessed";
863950
my ($dir, $file) = SearchFor('include', 'mysql.h');
@@ -900,7 +987,7 @@ section "Linker flags" or type
900987
perl Makefile.PL --help
901988
MSG
902989
}
903-
elsif ($param eq "testhost" || $param eq "testport" || $param eq "testsocket" || $param eq "testauthplugin") {
990+
elsif (grep { $param eq $_ } ("testhost", "testport", "testsocket", "testembdatadir")) {
904991
# known parameter, but do nothing
905992
}
906993
else {

0 commit comments

Comments
 (0)