Test-Dynamic

 view release on metacpan or  search on metacpan

t/bucardo.testfile  view on Meta::CPAN

		redo;
	}

	return;

} ## end of shutdown_bucardo


sub wait_until_true {

	my $xline = (caller)[2];
	my $dbh = shift or die "Need a database handle (from line $xline)\n";
	my $sql = shift or die "Need a SQL statement (from line $xline)\n";
	my $timeout = shift || $TIMEOUT_SYNCWAIT;
	my $sleep = shift || $TIMEOUT_SLEEP;
	my $type = shift || 'true';
	my $line = shift || $xline;

	alarm $timeout;
	$sth = $dbh->prepare($sql);
	eval {

t/bucardo.testfile  view on Meta::CPAN

	return $count unless $@;
	my $db = $dbmap{$dbh} || '?';
	BAIL_OUT (qq{Gave up waiting for "$sql" on db "$db" to be $type: timed out at $timeout from line $line ($@)});
	return;

} ## end of wait_until_true


sub wait_until_false {

	my $xline = (caller)[2];
	my $dbh = shift or die "Need a database handle (from line $xline)\n";
	my $sql = shift or die "Need a SQL statement (from line $xline)\n";
	my $timeout = shift || $TIMEOUT_SYNCWAIT;
	my $sleep = shift || $TIMEOUT_SLEEP;
	return wait_until_true($dbh,$sql,$timeout,$sleep,'false',$xline);

} ## end of wait_until_false

sub clean_all_tables {

t/bucardo.testfile  view on Meta::CPAN

	  N: {
			while ($n = $dbh->func('pg_notifies')) {
				last N if $n->[0] eq $text;
			}
			sleep $sleep;
			redo;
		}
	};
	$count = alarm 0;
	return $count unless $@;
	my $line = (caller)[2];
	BAIL_OUT (qq{Gave up waiting for notice "$text": timed out at $timeout from line $line ($@)});
	return;

} ## end of wait_for_notice


## no critic
{
	no warnings; ## Yes, we know they are being redefined!
	sub is_deeply {
		t($_[2],$_[3] || (caller)[2]);
		return if Test::More::is_deeply($_[0],$_[1],$testmsg);
		if ($bail_on_error > $total_errors++) {
			my $line = (caller)[2];
			my $time = time;
			diag("GOT: ".Dumper $_[0]);
			diag("EXPECTED: ". Dumper $_[1]);
			BAIL_OUT "Stopping on a failed 'is_deeply' test from line $line. Time: $time";
		}
	} ## end of is_deeply
	sub like {
		t($_[2],(caller)[2]);
		return if Test::More::like($_[0],$_[1],$testmsg);
		if ($bail_on_error > $total_errors++) {
			my $line = (caller)[2];
			my $time = time;
			BAIL_OUT "Stopping on a failed 'like' test from line $line. Time: $time";
		}
	} ## end of like
	sub pass {
		t($_[0],$_[1]||(caller)[2]);
		Test::More::pass($testmsg);
	} ## end of pass
	sub is {
		t($_[2],(caller)[2]);
		return if Test::More::is($_[0],$_[1],$testmsg);
		if ($bail_on_error > $total_errors++) {
			my $line = (caller)[2];
			my $time = time;
			BAIL_OUT "Stopping on a failed 'is' test from line $line. Time: $time";
		}
	} ## end of is
	sub isa_ok {
		t("Object isa $_[1]",(caller)[2]);
		my ($name, $type, $msg) = ($_[0],$_[1]);
		if (ref $name and ref $name eq $type) {
			Test::More::pass($testmsg);
			return;
		}
		$bail_on_error > $total_errors++ and BAIL_OUT "Stopping on a failed test";
	} ## end of isa_ok
	sub ok {
		t($_[1]||$testmsg);
		return if Test::More::ok($_[0],$testmsg);
		if ($bail_on_error > $total_errors++) {
			my $line = (caller)[2];
			my $time = time;
			BAIL_OUT "Stopping on a failed 'ok' test from line $line. Time: $time";
		}
	} ## end of ok
}
## use critic


sub now_time {
	my $dbh = shift;
	return $dbh->selectall_arrayref("SELECT now()")->[0][0];
} ## end of now_time


sub bc_deeply {

	my ($exp,$dbh,$sql,$msg) = @_;
	my $line = (caller)[2];

	local $Data::Dumper::Terse = 1;
	local $Data::Dumper::Indent = 0;

	die "Very invalid statement from line $line: $sql\n" if $sql !~ /^\s*select/i;

	my $got;
	eval {
		$got = $dbh->selectall_arrayref($sql);
	};
	if ($@) {
		die "bc_deeply failed from line $line. SQL=$sql\n";
	}

	return is_deeply($got,$exp,$msg,(caller)[2]);

} ## end of bc_deeply


sub compare_tables {

	my ($table,$sdbh,$rdbh) = @_;

	my ($line) = (caller)[2];

	local $Data::Dumper::Terse = 1;
	local $Data::Dumper::Indent = 0;

	my $msg = "Table $table is the same on both databases";
	$SQL = "SELECT * FROM $table ORDER BY inty, id";
	$SQL =~ s/inty, // if $table =~ /0/;
	my $uno = $sdbh->selectall_arrayref($SQL);
	my $dos = $rdbh->selectall_arrayref($SQL);
	if ((Dumper $uno) eq (Dumper $dos)) {

t/bucardo.testfile  view on Meta::CPAN

		delete $timing{$name};
	}
	else {
		$timing{$name} = [gettimeofday];
	}
	return;
} ## end of tt

sub t {
	$testmsg = shift;
	$testline = shift || (caller)[2];
	$testmsg =~ s/^\s+//;
	if ($location) {
		$testmsg = "($location) $testmsg";
	}
	if ($showline) {
		$testmsg .= " [line: $testline]";
	}
	if ($showtime) {
		my $time = time;
		$testmsg .= " [time: $time]";

t/bucardo.testfile.2  view on Meta::CPAN

		redo;
	}

	return;

} ## end of shutdown_bucardo


sub wait_until_true {

	my $xline = (caller)[2];
	my $dbh = shift or die "Need a database handle (from line $xline)\n";
	my $sql = shift or die "Need a SQL statement (from line $xline)\n";
	my $timeout = shift || $TIMEOUT_SYNCWAIT;
	my $sleep = shift || $TIMEOUT_SLEEP;
	my $type = shift || 'true';
	my $line = shift || $xline;

	alarm $timeout;
	$sth = $dbh->prepare($sql);
	eval {

t/bucardo.testfile.2  view on Meta::CPAN

	return $count unless $@;
	my $db = $dbmap{$dbh} || '?';
	BAIL_OUT (qq{Gave up waiting for "$sql" on db "$db" to be $type: timed out at $timeout from line $line ($@)});
	return;

} ## end of wait_until_true


sub wait_until_false {

	my $xline = (caller)[2];
	my $dbh = shift or die "Need a database handle (from line $xline)\n";
	my $sql = shift or die "Need a SQL statement (from line $xline)\n";
	my $timeout = shift || $TIMEOUT_SYNCWAIT;
	my $sleep = shift || $TIMEOUT_SLEEP;
	return wait_until_true($dbh,$sql,$timeout,$sleep,'false',$xline);

} ## end of wait_until_false

sub clean_all_tables {

t/bucardo.testfile.2  view on Meta::CPAN

	  N: {
			while ($n = $dbh->func('pg_notifies')) {
				last N if $n->[0] eq $text;
			}
			sleep $sleep;
			redo;
		}
	};
	$count = alarm 0;
	return $count unless $@;
	my $line = (caller)[2];
	BAIL_OUT (qq{Gave up waiting for notice "$text": timed out at $timeout from line $line ($@)});
	return;

} ## end of wait_for_notice


## no critic
{
	no warnings; ## Yes, we know they are being redefined!
	sub is_deeply {
		t($_[2],$_[3] || (caller)[2]);
		return if Test::More::is_deeply($_[0],$_[1],$testmsg);
		if ($bail_on_error > $total_errors++) {
			my $line = (caller)[2];
			my $time = time;
			diag("GOT: ".Dumper $_[0]);
			diag("EXPECTED: ". Dumper $_[1]);
			BAIL_OUT "Stopping on a failed 'is_deeply' test from line $line. Time: $time";
		}
	} ## end of is_deeply
	sub like {
		t($_[2],(caller)[2]);
		return if Test::More::like($_[0],$_[1],$testmsg);
		if ($bail_on_error > $total_errors++) {
			my $line = (caller)[2];
			my $time = time;
			BAIL_OUT "Stopping on a failed 'like' test from line $line. Time: $time";
		}
	} ## end of like
	sub pass {
		t($_[0],$_[1]||(caller)[2]);
		Test::More::pass($testmsg);
	} ## end of pass
	sub is {
		t($_[2],(caller)[2]);
		return if Test::More::is($_[0],$_[1],$testmsg);
		if ($bail_on_error > $total_errors++) {
			my $line = (caller)[2];
			my $time = time;
			BAIL_OUT "Stopping on a failed 'is' test from line $line. Time: $time";
		}
	} ## end of is
	sub isa_ok {
		t("Object isa $_[1]",(caller)[2]);
		my ($name, $type, $msg) = ($_[0],$_[1]);
		if (ref $name and ref $name eq $type) {
			Test::More::pass($testmsg);
			return;
		}
		$bail_on_error > $total_errors++ and BAIL_OUT "Stopping on a failed test";
	} ## end of isa_ok
	sub ok {
		t($_[1]||$testmsg);
		return if Test::More::ok($_[0],$testmsg);
		if ($bail_on_error > $total_errors++) {
			my $line = (caller)[2];
			my $time = time;
			BAIL_OUT "Stopping on a failed 'ok' test from line $line. Time: $time";
		}
	} ## end of ok
}
## use critic


sub now_time {
	my $dbh = shift;
	return $dbh->selectall_arrayref("SELECT now()")->[0][0];
} ## end of now_time


sub bc_deeply {

	my ($exp,$dbh,$sql,$msg) = @_;
	my $line = (caller)[2];

	local $Data::Dumper::Terse = 1;
	local $Data::Dumper::Indent = 0;

	die "Very invalid statement from line $line: $sql\n" if $sql !~ /^\s*select/i;

	my $got;
	eval {
		$got = $dbh->selectall_arrayref($sql);
	};
	if ($@) {
		die "bc_deeply failed from line $line. SQL=$sql\n";
	}

	return is_deeply($got,$exp,$msg,(caller)[2]);

} ## end of bc_deeply


sub compare_tables {

	my ($table,$sdbh,$rdbh) = @_;

	my ($line) = (caller)[2];

	local $Data::Dumper::Terse = 1;
	local $Data::Dumper::Indent = 0;

	my $msg = "Table $table is the same on both databases";
	$SQL = "SELECT * FROM $table ORDER BY inty, id";
	$SQL =~ s/inty, // if $table =~ /0/;
	my $uno = $sdbh->selectall_arrayref($SQL);
	my $dos = $rdbh->selectall_arrayref($SQL);
	if ((Dumper $uno) eq (Dumper $dos)) {

t/bucardo.testfile.2  view on Meta::CPAN

		delete $timing{$name};
	}
	else {
		$timing{$name} = [gettimeofday];
	}
	return;
} ## end of tt

sub t {
	$testmsg = shift;
	$testline = shift || (caller)[2];
	$testmsg =~ s/^\s+//;
	if ($location) {
		$testmsg = "($location) $testmsg";
	}
	if ($showline) {
		$testmsg .= " [line: $testline]";
	}
	if ($showtime) {
		my $time = time;
		$testmsg .= " [time: $time]";

t/bucardo.testfile.3  view on Meta::CPAN

		redo;
	}

	return;

} ## end of shutdown_bucardo


sub wait_until_true {

	my $xline = (caller)[2];
	my $dbh = shift or die "Need a database handle (from line $xline)\n";
	my $sql = shift or die "Need a SQL statement (from line $xline)\n";
	my $timeout = shift || $TIMEOUT_SYNCWAIT;
	my $sleep = shift || $TIMEOUT_SLEEP;
	my $type = shift || 'true';
	my $line = shift || $xline;

	alarm $timeout;
	$sth = $dbh->prepare($sql);
	eval {

t/bucardo.testfile.3  view on Meta::CPAN

	return $count unless $@;
	my $db = $dbmap{$dbh} || '?';
	BAIL_OUT (qq{Gave up waiting for "$sql" on db "$db" to be $type: timed out at $timeout from line $line ($@)});
	return;

} ## end of wait_until_true


sub wait_until_false {

	my $xline = (caller)[2];
	my $dbh = shift or die "Need a database handle (from line $xline)\n";
	my $sql = shift or die "Need a SQL statement (from line $xline)\n";
	my $timeout = shift || $TIMEOUT_SYNCWAIT;
	my $sleep = shift || $TIMEOUT_SLEEP;
	return wait_until_true($dbh,$sql,$timeout,$sleep,'false',$xline);

} ## end of wait_until_false

sub clean_all_tables {

t/bucardo.testfile.3  view on Meta::CPAN

	  N: {
			while ($n = $dbh->func('pg_notifies')) {
				last N if $n->[0] eq $text;
			}
			sleep $sleep;
			redo;
		}
	};
	$count = alarm 0;
	return $count unless $@;
	my $line = (caller)[2];
	BAIL_OUT (qq{Gave up waiting for notice "$text": timed out at $timeout from line $line ($@)});
	return;

} ## end of wait_for_notice


## no critic
{
	no warnings; ## Yes, we know they are being redefined!
	sub is_deeply {
		t($_[2],$_[3] || (caller)[2]);
		return if Test::More::is_deeply($_[0],$_[1],$testmsg);
		if ($bail_on_error > $total_errors++) {
			my $line = (caller)[2];
			my $time = time;
			diag("GOT: ".Dumper $_[0]);
			diag("EXPECTED: ". Dumper $_[1]);
			BAIL_OUT "Stopping on a failed 'is_deeply' test from line $line. Time: $time";
		}
	} ## end of is_deeply
	sub like {
		t($_[2],(caller)[2]);
		return if Test::More::like($_[0],$_[1],$testmsg);
		if ($bail_on_error > $total_errors++) {
			my $line = (caller)[2];
			my $time = time;
			BAIL_OUT "Stopping on a failed 'like' test from line $line. Time: $time";
		}
	} ## end of like
	sub pass {
		t($_[0],$_[1]||(caller)[2]);
		Test::More::pass($testmsg);
	} ## end of pass
	sub is {
		t($_[2],(caller)[2]);
		return if Test::More::is($_[0],$_[1],$testmsg);
		if ($bail_on_error > $total_errors++) {
			my $line = (caller)[2];
			my $time = time;
			BAIL_OUT "Stopping on a failed 'is' test from line $line. Time: $time";
		}
	} ## end of is
	sub isa_ok {
		t("Object isa $_[1]",(caller)[2]);
		my ($name, $type, $msg) = ($_[0],$_[1]);
		if (ref $name and ref $name eq $type) {
			Test::More::pass($testmsg);
			return;
		}
		$bail_on_error > $total_errors++ and BAIL_OUT "Stopping on a failed test";
	} ## end of isa_ok
	sub ok {
		t($_[1]||$testmsg);
		return if Test::More::ok($_[0],$testmsg);
		if ($bail_on_error > $total_errors++) {
			my $line = (caller)[2];
			my $time = time;
			BAIL_OUT "Stopping on a failed 'ok' test from line $line. Time: $time";
		}
	} ## end of ok
}
## use critic


sub now_time {
	my $dbh = shift;
	return $dbh->selectall_arrayref("SELECT now()")->[0][0];
} ## end of now_time


sub bc_deeply {

	my ($exp,$dbh,$sql,$msg) = @_;
	my $line = (caller)[2];

	local $Data::Dumper::Terse = 1;
	local $Data::Dumper::Indent = 0;

	die "Very invalid statement from line $line: $sql\n" if $sql !~ /^\s*select/i;

	my $got;
	eval {
		$got = $dbh->selectall_arrayref($sql);
	};
	if ($@) {
		die "bc_deeply failed from line $line. SQL=$sql\n";
	}

	return is_deeply($got,$exp,$msg,(caller)[2]);

} ## end of bc_deeply


sub compare_tables {

	my ($table,$sdbh,$rdbh) = @_;

	my ($line) = (caller)[2];

	local $Data::Dumper::Terse = 1;
	local $Data::Dumper::Indent = 0;

	my $msg = "Table $table is the same on both databases";
	$SQL = "SELECT * FROM $table ORDER BY inty, id";
	$SQL =~ s/inty, // if $table =~ /0/;
	my $uno = $sdbh->selectall_arrayref($SQL);
	my $dos = $rdbh->selectall_arrayref($SQL);
	if ((Dumper $uno) eq (Dumper $dos)) {

t/bucardo.testfile.3  view on Meta::CPAN

		delete $timing{$name};
	}
	else {
		$timing{$name} = [gettimeofday];
	}
	return;
} ## end of tt

sub t {
	$testmsg = shift;
	$testline = shift || (caller)[2];
	$testmsg =~ s/^\s+//;
	if ($location) {
		$testmsg = "($location) $testmsg";
	}
	if ($showline) {
		$testmsg .= " [line: $testline]";
	}
	if ($showtime) {
		my $time = time;
		$testmsg .= " [time: $time]";



( run in 1.867 second using v1.01-cache-2.11-cpan-a3c8064c92c )