0

我有这个脚本:

#!/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 的实例正在运行。我什至不知道从哪里开始解决这个问题。有什么提示吗?

4

1 回答 1

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;
};
于 2012-06-22T21:00:54.197 回答