Test :: mysqld不会按预期关闭mysqld

时间:2012-06-22 19:53:05

标签: perl unit-testing mysql

我有这个脚本:

#!/var/home/cherry/opt/perl

use Test::More;
use DBI;
use Test::mysqld;
use Data::Dumper;

my $mysqld = Test::mysqld->new(
    base_dir => '/tmp/test_mysqls',
    my_cnf => {
        'skip-networking' => '', # no TCP socket
    }
) or plan skip_all => $Test::mysqld::errstr;

my $dbh = DBI->connect(
    $mysqld->dsn(dbname => 'test'),
);

warn Dumper($mysqld);

done_testing();

当我运行时,这是我得到的输出:

prove -lv t/test.t
t/test.t .. $VAR1 = bless( {
                 '_owner_pid' => 21854,
                 'base_dir' => '/tmp/test_mysqls',
                 'pid' => 21918,
                 'mysql_install_db' => '/usr/bin/mysql_install_db',
                 'auto_start' => 2,
                 'my_cnf' => {
                               'tmpdir' => '/tmp/test_mysqls/tmp',
                               'pid-file' => '/tmp/test_mysqls/tmp/mysqld.pid',
                               'skip-networking' => '',
                               'datadir' => '/tmp/test_mysqls/var',
                               'socket' => '/tmp/test_mysqls/tmp/mysql.sock'
                             },
                 'mysqld' => '/usr/sbin/mysqld'
               }, 'Test::mysqld' );

1..0

测试永远不会完成。脚本永远等待换行符并且永不退出 - 当我执行ps aux时,即使在我执行ctrl + c之后,我也可以看到mysqld的实例正在运行。我甚至不知道从哪里开始解决这个问题。任何提示?

1 个答案:

答案 0 :(得分:0)

尝试添加do {}并在eval {}内调用$ mysqld-> stop来关闭mysqld。

my $mysqld = Test::mysqld->new(
    base_dir => '/tmp/test_mysqls',
    my_cnf => {
        'skip-networking' => '', # no TCP socket
    }
) or do {
    eval { $mysqld->stop };
    plan skip_all => $Test::mysqld::errstr;
};