Rewrite t/pt-archiver/standard_options.t to make it reliable.

This commit is contained in:
Daniel Nichter
2012-12-06 10:02:24 -07:00
parent 4903cc034b
commit 97e0529798
2 changed files with 104 additions and 60 deletions

View File

@@ -126,12 +126,13 @@ sub create_dbs {
}
sub get_dbh_for {
my ( $self, $server, $cxn_ops ) = @_;
my ( $self, $server, $cxn_ops, $user ) = @_;
_check_server($server);
$cxn_ops ||= { AutoCommit => 1 };
$user ||= 'msandbox';
PTDEBUG && _d('dbh for', $server, 'on port', $port_for{$server});
my $dp = $self->{DSNParser};
my $dsn = $dp->parse('h=127.0.0.1,u=msandbox,p=msandbox,P=' . $port_for{$server});
my $dsn = $dp->parse("h=127.0.0.1,u=$user,p=msandbox,P=" . $port_for{$server});
my $dbh;
# This is primarily for the benefit of CompareResults, but it's
# also quite convenient when using an affected OS
@@ -542,6 +543,23 @@ sub config_file_for {
return "/tmp/$port/my.sandbox.cnf"
}
sub do_as_root {
my ($self, $server, @queries) = @_;
my $dbh = $self->get_dbh_for($server, undef, 'root');
my $ok = 1;
eval {
foreach my $query ( @queries ) {
$dbh->do($query);
}
};
if ( $EVAL_ERROR ) {
$ok = 0;
warn $EVAL_ERROR;
}
$dbh->disconnect;
return $ok;
}
sub _d {
my ($package, undef, $line) = caller 0;
@_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }