1--source include/not_embedded.inc
2let $MYSQLD_DATADIR= `select @@datadir`;
3let MYSQLDDATADIR= `select @@datadir`;
4
5--echo ##########################################
6--echo # Run plugin
7--echo ##########################################
8--replace_result $TEST_SQL_SHUTDOWN TEST_SQL_SHUTDOWN
9eval INSTALL PLUGIN test_sql_shutdown SONAME '$TEST_SQL_SHUTDOWN';
10# Wait until the plugin thread has opened a session.
11# That's for the deterministic result also on slow machines.
12let $wait_condition= SELECT count(*) > 0 FROM information_schema.processlist WHERE info LIKE 'PLUGIN%';
13--source include/wait_condition.inc
14SELECT count(*) FROM information_schema.processlist WHERE info LIKE 'PLUGIN%';
15--echo ##########################################
16--echo # Shutdown
17--echo ##########################################
18--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
19--shutdown_server
20--source include/wait_until_disconnected.inc
21# Give implicitly called deinit of plugin time to write 'SERVER SHUTDOWN' to file
22# The following perl snippet is waiting until the test plugin will be ready
23# to write into the log. The last line must contain "SERVER SHUTDOWN".
24# Then the test can cat the file content into the result file.
25perl;
26    use strict;
27    my $max_trials= 300;
28    my $fc_count= 0;
29    my $p_found= 1;
30    my $fn= "$ENV{'MYSQLDDATADIR'}/test_sql_shutdown.log";
31    my $search_pattern="SERVER SHUTDOWN";
32    while ($p_found and $fc_count < $max_trials) {
33         open(FILE, "<", $fn);
34         while (<FILE>) {
35              if (m{$search_pattern}) {
36                 $p_found= 0;
37                 close(FILE);
38                 exit;
39              }
40         }
41         sleep(1);
42         $fc_count++;
43         close(FILE);
44    }
45    print "Pattern \"$search_pattern\" not found\n";
46EOF
47cat_file $MYSQLD_DATADIR/test_sql_shutdown.log;
48
49
50--echo ##########################################
51--echo # Restart
52--echo ##########################################
53--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
54--enable_reconnect
55--source include/wait_until_connected_again.inc
56cat_file $MYSQLD_DATADIR/test_sql_shutdown.log;
57
58SELECT plugin_name, plugin_status, plugin_type,
59       plugin_description, load_option
60FROM information_schema.plugins
61WHERE plugin_name LIKE "test_sql_shutdown";
62
63--echo ##########################################
64--echo # Stop plugin
65--echo ##########################################
66UNINSTALL PLUGIN test_sql_shutdown;
67remove_file $MYSQLD_DATADIR/test_sql_shutdown.log;
68