From: Greg Sabino Mullane Date: Mon, 7 Jul 2014 15:48:53 +0000 (-0400) Subject: Further work on conflict testing. X-Git-Tag: 5.1.0~8 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=68243f48b00ce32f5cc3f9e8a63f79072e197461;p=bucardo.git Further work on conflict testing. --- diff --git a/MANIFEST b/MANIFEST index 5f8c87c4d..55c5e6558 100644 --- a/MANIFEST +++ b/MANIFEST @@ -53,6 +53,9 @@ t/98-cleanup.t t/99-signature.t t/BucardoTesting.pm t/customcode.exception.bucardotest.pl +t/ctest1.pl +t/ctest2.pl +t/ctest3.pl test_setup.sh TODO UPGRADE diff --git a/t/40-conflict.t b/t/40-conflict.t index fc96eb316..250423d1a 100644 --- a/t/40-conflict.t +++ b/t/40-conflict.t @@ -83,7 +83,8 @@ $bct->add_row_to_database('B', 2); $bct->add_row_to_database('C', 2); $bct->ctl('bucardo kick sync ctest 10'); -$bct->check_for_row([[1],[2]], [qw/ B C D/]); + +$bct->check_for_row([[1],[2]], [qw/ A B C D/]); $t = q{Cannot set conflict handler to invalid database name}; $res = $bct->ctl('bucardo update sync ctest conflict="a b c"'); @@ -110,5 +111,66 @@ $bct->update_row_in_database('B', 1, 2222); $bct->ctl('bucardo kick sync ctest 10'); $bct->check_for_row([[2],[1111]], [qw/ A B C D/]); +## Test of the default conflict strategy +$bct->update_row_in_database('B', 1, 102); +$bct->update_row_in_database('A', 2, 201); +$bct->update_row_in_database('B', 2, 202); +$bct->add_row_to_database('A', 3); +$bct->update_row_in_database('A', 3, 301); +$bct->update_row_in_database('C', 2, 203); + +$t = q{Set conflict strategy to 'bucardo_latest'}; +$res = $bct->ctl('bucardo update sync ctest conflict=latest'); +like($res, qr{Set conflict strategy to 'bucardo_latest'}, $t); + +$t = q{Reloaded sync ctest}; +$res = $bct->ctl('bucardo reload sync ctest'); +like($res, qr{success}, $t); + +## Database B should be the winner for 1, C for 2, and A for 3 +$bct->ctl('bucardo kick sync ctest 10'); +$bct->check_for_row([[102],[203],[301]], [qw/ A B C D /]); + +## Test of conflict handler 'bucardo_latest_all_tables' +$t = q{Set conflict strategy to 'bucardo_latest_all_tables'}; +$res = $bct->ctl('bucardo update sync ctest conflict=latest_all'); +like($res, qr{Set conflict strategy to 'bucardo_latest_all_tables'}, $t); + +$t = q{Reloaded sync ctest}; +$res = $bct->ctl('bucardo reload sync ctest'); +like($res, qr{success}, $t); + +$bct->update_row_in_database('B', 1, 102); +$bct->update_row_in_database('A', 2, 201); +$bct->update_row_in_database('B', 2, 202); +$bct->update_row_in_database('A', 3, 301); +$bct->update_row_in_database('C', 2, 203); + +## Database B should be the winner for 1, C for 2, and A for 3 +$bct->ctl('bucardo kick sync ctest 10'); +$bct->check_for_row([[102],[203],[301]], [qw/ A B C D /]); + +## Use a custom conflict handler by adding a customcode to this sync +$t = q{Added new customcode ctest1 for conflict in the ctest sync}; +$res = $bct->ctl('bucardo add customcode ctest1 whenrun=conflict sync=ctest src_code=t/ctest1.pl'); +like($res, qr{Added customcode "ctest1"}, $t); + +$t = q{Reloaded sync ctest}; +$res = $bct->ctl('bucardo reload sync ctest'); +like($res, qr{success}, $t); + +$bct->update_row_in_database('A', 2, 211); +$bct->update_row_in_database('B', 2, 212); +$bct->update_row_in_database('C', 2, 213); +$bct->update_row_in_database('A', 1, 111); +$bct->update_row_in_database('C', 1, 113); +$bct->ctl('bucardo kick sync ctest 10'); +$bct->check_for_row([[111],[212],[301]], [qw/ A B C D /]); + +## Customcode with winner + +## Customcode on a goat only + + done_testing(); exit; diff --git a/t/ctest1.pl b/t/ctest1.pl new file mode 100644 index 000000000..d070bb65b --- /dev/null +++ b/t/ctest1.pl @@ -0,0 +1,16 @@ +## ctest1.pl - a conflict handler for Bucardo +use strict; +use warnings; + +my $info = shift; + +## If this table is named 'work', do nothing +if ($info->{tablename} eq 'work') { + $info->{skip} = 1; +} +else { + ## Winning databases, in order + $info->{winner} = 'B A C'; +} + +return; diff --git a/t/ctest2.pl b/t/ctest2.pl new file mode 100644 index 000000000..e69de29bb diff --git a/t/ctest3.pl b/t/ctest3.pl new file mode 100644 index 000000000..e69de29bb